Skip to content

Commit a6ecddf

Browse files
committed
Update jenkinsfile
1 parent b6618c2 commit a6ecddf

File tree

6 files changed

+92
-16
lines changed

6 files changed

+92
-16
lines changed

Jenkinsfile

Lines changed: 59 additions & 10 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
@@ -36,45 +74,56 @@ pipeline {
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
)
3876
script {
39-
releaseStatus = sh(script: './simple-relmgt check', returnStatus: true)
77+
if (officialReleaseFileFound == 0) {
78+
echo('Using built simple-relmgt...')
79+
releaseStatus = sh(script: releaseCmdPath + ' check', returnStatus: true)
80+
}
81+
4082
}
4183
}
4284
}
43-
/* stage('Release PR status') {
85+
86+
stage('Release PR status from built binary') {
4487
when {
4588
changeRequest target: 'master'
89+
expression { return officialReleaseFileFound != 0 }
4690
}
4791
steps {
48-
sh('./simple-relmgt status')
92+
sh(releaseCmdPath + ' status')
4993
}
5094
}
51-
/* stage('tag it') {
95+
96+
stage('tag it') {
5297
when {
5398
branch 'master'
54-
environment name: 'RELEASE_STATUS', value: '0'
99+
expression { return releaseStatus == 0 }
55100
}
56101
steps {
57-
sh('simple-relmgt tag-it') // git tag, push it and create a draft github release
102+
sh(releaseCmdPath + ' tag-it') // git tag, push it and create a draft github release
58103
}
59-
}*/
104+
}
60105

61106
stage('Deploy') {
62-
when { branch 'master' }
107+
when {
108+
branch 'master'
109+
expression { return releaseStatus == 0 }
110+
}
63111
steps {
64112
withCredentials([
65113
usernamePassword(credentialsId: 'github-jenkins-cred', usernameVariable: 'GITHUB_USER', passwordVariable: 'GITHUB_TOKEN')
66114
]) {
67115
sh('''#!/bin/bash -e
68116
source ./build-env.sh
69117
publish.sh latest''')
118+
sh(releaseCmdPath + ' release-it') // release the draft github release
70119
}
71120
}
72121
}
73122
}
74123

75-
/* post {
124+
post {
76125
success {
77126
deleteDir()
78127
}
79-
}*/
128+
}
80129
}

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)