1
- /*
2
- sudo apt install ghp-import
3
- */
4
1
pipeline {
5
- agent any
6
-
7
- tools {
8
- go ' go-1.10'
9
- }
10
-
11
- options {
12
- skipDefaultCheckout true
2
+ agent {
3
+ dockerfile {
4
+ filename ' Dockerfile.build'
5
+ customWorkspace " /var/jenkins_home/go/src/github.com/bozaro/tech-db-forum"
6
+ }
13
7
}
14
8
15
9
parameters {
16
10
string(name : ' TAG_NAME' , defaultValue : ' ' , description : ' Tag name' )
17
11
}
18
12
19
13
environment {
20
- GOPATH = " $W ORKSPACE "
14
+ HOME = " /var/jenkins_home "
21
15
PROJ = " github.com/bozaro/tech-db-forum"
22
- PATH = " $G OPATH /bin: $P ATH "
16
+ GOPATH = " /var/jenkins_home/go "
23
17
}
24
18
25
19
stages {
26
- stage(' Checkout' ) {
27
- steps {
28
- checkout([
29
- $class : ' GitSCM' ,
30
- branches : scm. branches,
31
- extensions : scm. extensions + [[$class : ' LocalBranch' ], [$class : ' CleanCheckout' ], [$class : ' RelativeTargetDirectory' , relativeTargetDir : " src/${ PROJ} " ]],
32
- userRemoteConfigs : scm. userRemoteConfigs
33
- ])
34
- }
35
- }
36
20
stage(' Prepare' ) {
37
21
steps {
38
- dir( " src/ ${ PROJ } " ) {
39
- sh """
22
+ sh """
23
+ export PATH= \$ GOPATH/bin: \$ PATH
40
24
go install -v ./vendor/github.com/go-swagger/go-swagger/cmd/swagger
41
25
go install -v ./vendor/github.com/jteeuwen/go-bindata/go-bindata
42
26
go install -v ./vendor/github.com/mailru/easyjson/easyjson
43
27
go install -v ./vendor/github.com/aktau/github-release
44
28
go generate -x .
29
+ mkdir -p target/dist
45
30
"""
46
- }
47
- dir(" src/${ PROJ} /target/dist" ) {
48
- sh " true"
49
- }
50
31
}
51
32
}
52
33
stage(' Build' ) {
@@ -59,29 +40,12 @@ go generate -x .
59
40
SUFFIX = " "
60
41
}
61
42
steps {
62
- dir(" src/${ PROJ} " ) {
63
- sh """
64
- go build -ldflags " -X ${ PROJ} /tests.BuildTag=\$ {BUILD_TAG} -X ${ PROJ} /tests.GitCommit=\$ (git rev-parse HEAD)" -o build/\$ {GOOS}_\$ {GOARCH}/tech-db-forum\$ {SUFFIX}
65
- cd b
B022
uild/\$ {GOOS}_\$ {GOARCH}
66
- zip ../../target/dist/\$ {GOOS}_\$ {GOARCH}.zip tech-db-forum\$ {SUFFIX}
67
- """
68
- }
69
- }
70
- }
71
- stage(' linux_386' ) {
72
- environment {
73
- GOOS = " linux"
74
- GOARCH = " 386"
75
- SUFFIX = " "
76
- }
77
- steps {
78
- dir(" src/${ PROJ} " ) {
79
- sh """
43
+ sh """
44
+ export PATH=\$ GOPATH/bin:\$ PATH
80
45
go build -ldflags " -X ${ PROJ} /tests.BuildTag=\$ {BUILD_TAG} -X ${ PROJ} /tests.GitCommit=\$ (git rev-parse HEAD)" -o build/\$ {GOOS}_\$ {GOARCH}/tech-db-forum\$ {SUFFIX}
81
46
cd build/\$ {GOOS}_\$ {GOARCH}
82
47
zip ../../target/dist/\$ {GOOS}_\$ {GOARCH}.zip tech-db-forum\$ {SUFFIX}
83
48
"""
84
- }
85
49
}
86
50
}
87
51
stage(' linux_amd64' ) {
@@ -91,13 +55,12 @@ zip ../../target/dist/\${GOOS}_\${GOARCH}.zip tech-db-forum\${SUFFIX}
91
55
SUFFIX = " "
92
56
}
93
57
steps {
94
- dir( " src/ ${ PROJ } " ) {
95
- sh """
58
+ sh """
59
+ export PATH= \$ GOPATH/bin: \$ PATH
96
60
go build -ldflags " -X ${ PROJ} /tests.BuildTag=\$ {BUILD_TAG} -X ${ PROJ} /tests.GitCommit=\$ (git rev-parse HEAD)" -o build/\$ {GOOS}_\$ {GOARCH}/tech-db-forum\$ {SUFFIX}
97
61
cd build/\$ {GOOS}_\$ {GOARCH}
98
62
zip ../../target/dist/\$ {GOOS}_\$ {GOARCH}.zip tech-db-forum\$ {SUFFIX}
99
63
"""
100
- }
101
64
}
102
65
}
103
66
stage(' windows_386' ) {
@@ -107,13 +70,12 @@ zip ../../target/dist/\${GOOS}_\${GOARCH}.zip tech-db-forum\${SUFFIX}
107
70
SUFFIX = " .exe"
108
71
}
109
72
steps {
110
- dir( " src/ ${ PROJ } " ) {
111
- sh """
73
+ sh """
74
+ export PATH= \$ GOPATH/bin: \$ PATH
112
75
go build -ldflags " -X ${ PROJ} /tests.BuildTag=\$ {BUILD_TAG} -X ${ PROJ} /tests.GitCommit=\$ (git rev-parse HEAD)" -o build/\$ {GOOS}_\$ {GOARCH}/tech-db-forum\$ {SUFFIX}
113
76
cd build/\$ {GOOS}_\$ {GOARCH}
114
77
zip ../../target/dist/\$ {GOOS}_\$ {GOARCH}.zip tech-db-forum\$ {SUFFIX}
115
78
"""
116
- }
117
79
}
118
80
}
119
81
stage(' windows_amd64' ) {
@@ -123,39 +85,34 @@ zip ../../target/dist/\${GOOS}_\${GOARCH}.zip tech-db-forum\${SUFFIX}
123
85
SUFFIX = " .exe"
124
86
}
125
87
steps {
126
- dir( " src/ ${ PROJ } " ) {
127
- sh """
88
+ sh """
89
+ export PATH= \$ GOPATH/bin: \$ PATH
128
90
go build -ldflags " -X ${ PROJ} /tests.BuildTag=\$ {BUILD_TAG} -X ${ PROJ} /tests.GitCommit=\$ (git rev-parse HEAD)" -o build/\$ {GOOS}_\$ {GOARCH}/tech-db-forum\$ {SUFFIX}
129
91
cd build/\$ {GOOS}_\$ {GOARCH}
130
92
zip ../../target/dist/\$ {GOOS}_\$ {GOARCH}.zip tech-db-forum\$ {SUFFIX}
131
93
"""
132
- }
133
94
}
134
95
}
135
96
}
136
97
}
137
98
stage(' Prepare gp-pages' ) {
138
99
steps {
139
- dir(" src/${ PROJ} " ) {
140
- sh """
100
+ sh """
141
101
g
5B9E
it branch -fD gh-pages || true
142
102
git branch -rd origin/gh-pages || true
143
103
ghp-import -n target/dist
144
104
"""
145
- }
146
105
}
147
106
}
148
107
stage(' Publish gh-pages' ) {
149
108
when {
150
109
branch ' master'
151
110
}
152
111
steps {
153
- withCredentials([usernamePassword(credentialsId : ' 88e000b8-d989-4f94-b919-1cc1352a5f96' , passwordVariable : ' TOKEN' , usernameVariable : ' LOGIN' )]) {
154
- dir(" src/${ PROJ} " ) {
155
- sh """
156
- git push -qf https://\$ {TOKEN}@github.com/bozaro/tech-db-forum.git gh-pages
112
+ withCredentials([[$class : ' StringBinding' , credentialsId : ' github_bozaro' , variable : ' GITHUB_TOKEN' ]]) {
113
+ sh """
114
+ git push -qf https://\$ {GITHUB_TOKEN}@github.com/bozaro/tech-db-forum.git gh-pages
157
115
"""
158
- }
159
116
}
160
117
}
161
118
}
@@ -168,22 +125,23 @@ git push -qf https://\${TOKEN}@github.com/bozaro/tech-db-forum.git gh-pages
168
125
GITHUB_REPO = " tech-db-forum"
169
126
}
170
127
steps {
171
- withCredentials([[$class : ' StringBinding' , credentialsId : ' 49bf22be-f4d4-4a75-855a-b0e56e357f1c ' , variable : ' GITHUB_TOKEN' ]]) {
172
- dir( " src/ ${ PROJ } " ) {
173
- sh """
128
+ withCredentials([[$class : ' StringBinding' , credentialsId : ' github_bozaro ' , variable : ' GITHUB_TOKEN' ]]) {
129
+ sh """
130
+ export PATH= \$ GOPATH/bin: \$ PATH
174
131
github-release info --tag ${ params.TAG_NAME} || github-release release --tag ${ params.TAG_NAME} --draft
175
132
for i in target/dist/*.zip; do
176
133
github-release upload --tag ${ params.TAG_NAME} --file \$ i --name `basename \$ i`
177
134
done
135
+ git tag ${ params.TAG_NAME}
136
+ git push -qf https://\$ {GITHUB_TOKEN}@github.com/bozaro/tech-db-forum.git gh-pages ${ params.TAG_NAME}
178
137
"""
179
- }
180
138
}
181
139
}
182
140
}
183
141
}
184
142
post {
185
143
always {
186
- archiveArtifacts artifacts : " src/ ${ PROJ } / target/dist/*.zip" , fingerprint : true
144
+ archiveArtifacts artifacts : " target/dist/*.zip" , fingerprint : true
187
145
}
188
146
}
189
147
}
0 commit comments