Skip to content

Commit 347a4e7

Browse files
committed
Update jenkinsfile
1 parent b6618c2 commit 347a4e7

File tree

6 files changed

+92
-18
lines changed

6 files changed

+92
-18
lines changed

Jenkinsfile

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
def releaseStatus = 3 // Not a release branch
2+
def officialReleaseFileFound = 1
3+
def releaseCmdPath = 'tmp/simple-relmgt'
24

35
pipeline {
46
agent any
@@ -11,6 +13,42 @@ pipeline {
1113
create-go-build-env.sh''')
1214
}
1315
}
16+
17+
stage('prepare deployment environment') {
18+
steps {
19+
sh('''#!/bin/bash
20+
mkdir -p tmp
21+
rm -f tmp/simple-relmgt
22+
curl -L -s -O tmp/simple-relmgt https://github.com/forj-oss/simple-relmgt/releases/download/latest/simple-relmgt >/dev/null
23+
if [[ -f tmp/simple-relmgt ]]
24+
then
25+
chmod +x tmp/simple-relmgt
26+
tmp/simple-relmgt --version
27+
else
28+
echo "No official simple-relmgt found. Using local built one."
29+
exit 0
30+
fi
31+
''')
32+
33+
script {
34+
officialReleaseFileFound = sh(script: '[ -f ' + releaseCmdPath + ' ]', returnStatus: true)
35+
if (officialReleaseFileFound == 0) {
36+
releaseStatus = sh(script: releaseCmdPath + ' check', returnStatus: true)
37+
} else {
38+
releaseCmdPath = "./simple-relmgt"
39+
}
40+
}
41+
}
42+
}
43+
stage('Release PR status') {
44+
when {
45+
changeRequest target: 'master'
46+
expression { return officialReleaseFileFound == 0 }
47+
}
48+
steps {
49+
sh(releaseCmdPath + ' status')
50+
}
51+
}
1452
stage('Install dependencies') {
1553
steps {
1654
sh('''#!/bin/bash -e
@@ -35,46 +73,55 @@ pipeline {
3573
source ./build-env.sh
3674
go test simple-relmgt simple-relmgt/cmds/draftcmd simple-relmgt/cmds/checkcmd simple-relmgt/cmds/releasecmd simple-relmgt/cmds/statecmd simple-relmgt/cmds/tagcmd'''
3775
)
38-
script {
39-
releaseStatus = sh(script: './simple-relmgt check', returnStatus: true)
40-
}
4176
}
4277
}
43-
/* stage('Release PR status') {
78+
79+
stage('Release PR status from built binary') {
4480
when {
4581
changeRequest target: 'master'
82+
expression { return officialReleaseFileFound != 0 }
4683
}
4784
steps {
48-
sh('./simple-relmgt status')
85+
script {
86+
if (officialReleaseFileFound == 0) {
87+
echo('Using built simple-relmgt...')
88+
releaseStatus = sh(script: releaseCmdPath + ' check', returnStatus: true)
89+
}
90+
}
4991
}
5092
}
51-
/* stage('tag it') {
93+
94+
stage('tag it') {
5295
when {
5396
branch 'master'
54-
environment name: 'RELEASE_STATUS', value: '0'
97+
expression { return releaseStatus == 0 }
5598
}
5699
steps {
57-
sh('simple-relmgt tag-it') // git tag, push it and create a draft github release
100+
sh(releaseCmdPath + ' tag-it') // git tag, push it and create a draft github release
58101
}
59-
}*/
102+
}
60103

61104
stage('Deploy') {
62-
when { branch 'master' }
105+
when {
106+
branch 'master'
107+
expression { return releaseStatus == 0 }
108+
}
63109
steps {
64110
withCredentials([
65111
usernamePassword(credentialsId: 'github-jenkins-cred', usernameVariable: 'GITHUB_USER', passwordVariable: 'GITHUB_TOKEN')
66112
]) {
67113
sh('''#!/bin/bash -e
68114
source ./build-env.sh
69115
publish.sh latest''')
116+
sh(releaseCmdPath + ' release-it') // release the draft github release
70117
}
71118
}
72119
}
73120
}
74121

75-
/* post {
122+
post {
76123
success {
77124
deleteDir()
78125
}
79-
}*/
126+
}
80127
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ pipeline {
9999
returnStatus: true
100100
)
101101
}
102-
/* optional */
103102
stages {
103+
/* optional */
104104
stage('Release PR status') {
105105
when {
106106
changeRequest target: 'master'

cmds/draftcmd/draft.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package draftcmd
22

3-
import "github.com/alecthomas/kingpin"
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/alecthomas/kingpin"
8+
)
49

510
// Draft control the draft-it command
611
type Draft struct {
@@ -13,7 +18,8 @@ const (
1318

1419
// Action execute the `check` command
1520
func (c *Draft) Action([]string) {
16-
21+
fmt.Printf("%s not currently defined\n", DraftItCmd)
22+
os.Exit(5) // Function not defined
1723
}
1824

1925
// Init initialize the check cli commands

cmds/releasecmd/release.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package releasecmd
22

3-
import "github.com/alecthomas/kingpin"
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/alecthomas/kingpin"
8+
)
49

510
// Release control the release-it command
611
type Release struct {
@@ -13,6 +18,8 @@ const (
1318

1419
// Action execute the `check` command
1520
func (c *Release) Action([]string) {
21+
fmt.Printf("%s not currently defined\n", ReleaseItCmd)
22+
os.Exit(5) // Function not defined
1623

1724
}
1825

cmds/statecmd/state.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package statecmd
22

3-
import "github.com/alecthomas/kingpin"
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/alecthomas/kingpin"
8+
)
49

510
// State control the status command
611
type State struct {
@@ -13,6 +18,8 @@ const (
1318

1419
// Action execute the `check` command
1520
func (c *State) Action([]string) {
21+
fmt.Printf("%s not currently defined\n", StateItCmd)
22+
os.Exit(5) // Function not defined
1623

1724
}
1825

cmds/tagcmd/tag.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package tagcmd
22

3-
import "github.com/alecthomas/kingpin"
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/alecthomas/kingpin"
8+
)
49

510
// Tag control the tag-it command
611
type Tag struct {
@@ -13,6 +18,8 @@ const (
1318

1419
// Action execute the `check` command
1520
func (c *Tag) Action([]string) {
21+
fmt.Printf("%s not currently defined\n", TagItCmd)
22+
os.Exit(5) // Function not defined
1623

1724
}
1825

0 commit comments

Comments
 (0)