E58E Move to declarative pipeline · bozaro/tech-db-forum@b29d3fe · GitHub
[go: up one dir, main page]

Skip to content

Commit b29d3fe

Browse files
committed
Move to declarative pipeline
1 parent a5d4fc6 commit b29d3fe

File tree

1 file changed

+170
-78
lines changed

1 file changed

+170
-78
lines changed

Jenkinsfile

Lines changed: 170 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,189 @@
11
/*
22
sudo apt install ghp-import
33
*/
4-
goProject = "github.com/bozaro/tech-db-forum"
4+
pipeline {
5+
agent any
56

6-
properties([parameters([string(name: 'TAG_NAME', defaultValue: '')])])
7-
if (params.TAG_NAME != "") {
8-
echo "Build tag: ${params.TAG_NAME}"
9-
}
10-
11-
node ('linux') {
12-
stage ('Checkout') {
13-
checkout([
14-
$class: 'GitSCM',
15-
branches: scm.branches,
16-
doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
17-
extensions: scm.extensions + [
18-
[$class: 'CleanCheckout'],
19-
[$class: 'RelativeTargetDirectory', relativeTargetDir: "src/$goProject"],
20-
[$class: 'SubmoduleOption', disableSubmodules: false, recursiveSubmodules: false],
21-
],
22-
userRemoteConfigs: scm.userRemoteConfigs
23-
])
24-
}
25-
stage ('Prepare') {
26-
sh """
27-
export GOPATH="\$PWD"
28-
export PATH="\$GOPATH/bin:\$PATH"
29-
cd src/$goProject
30-
go install ./vendor/github.com/bronze1man/yaml2json
31-
go install ./vendor/github.com/aktau/github-release
32-
"""
33-
}
34-
stage ('Build') {
35-
sh """#!/bin/bash -ex
36-
export GOPATH="\$PWD"
37-
export PATH="\$GOPATH/bin:\$PATH"
38-
39-
cd src/$goProject
40-
41-
# Build application
42-
function go_build {
43-
GIT_COMMIT=`git rev-parse --verify HEAD`
44-
GOOS=\$1 GOARCH=\$2 go build -ldflags " -X github.com/bozaro/tech-db-forum/tests.BuildTag=\${BUILD_TAG} -X github.com/bozaro/tech-db-forum/tests.GitCommit=\${GIT_COMMIT}" -o build/\$1_\$2/tech-db-forum\$3
7+
tools {
8+
go 'go-1.10'
9+
}
4510

46-
pushd build/\$1_\$2
47-
zip ../../target/dist/\$1_\$2.zip tech-db-forum\$3
48-
popd
49-
}
11+
options {
12+
skipDefaultCheckout true
13+
}
5014

51-
rm -fR target/dist/
52-
mkdir -p target/dist/
15+
parameters {
16+
string(name: 'TAG_NAME', defaultValue: '', description: 'Tag name')
17+
}
5318

54-
go_build linux amd64
55-
go_build linux 386
56-
go_build darwin amd64
57-
go_build windows amd64 .exe
58-
go_build windows 386 .exe
19+
environment {
20+
GOPATH = "$WORKSPACE"
21+
PROJ = "github.com/bozaro/tech-db-forum"
22+
PATH = "$GOPATH/bin:$PATH"
23+
}
5924

25+
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+
stage('Prepare') {
37+
steps {
38+
dir("src/${PROJ}") {
39+
sh """
40+
go install -v ./vendor/github.com/go-swagger/go-swagger/cmd/swagger
41+
go install -v ./vendor/github.com/jteeuwen/go-bindata/go-bindata
42+
go install -v ./vendor/github.com/mailru/easyjson/easyjson
43+
go install -v ./vendor/github.com/aktau/github-release
44+
go generate -x .
45+
"""
46+
}
47+
dir("src/${PROJ}/target/dist") {
48+
sh "true"
49+
}
50+
}
51+
}
52+
stage('Build') {
53+
failFast true
54+
parallel {
55+
stage('darwin_amd64') {
56+
environment {
57+
GOOS = "darwin"
58+
GOARCH = "amd64"
59+
SUFFIX = ""
60+
}
61+
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 build/\${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+
6F26 }
77+
steps {
78+
dir("src/${PROJ}") {
79+
sh """
80+
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+
cd build/\${GOOS}_\${GOARCH}
82+
zip ../../target/dist/\${GOOS}_\${GOARCH}.zip tech-db-forum\${SUFFIX}
83+
"""
84+
}
85+
}
86+
}
87+
stage('linux_amd64') {
88+
environment {
89+
GOOS = "linux"
90+
GOARCH = "amd64"
91+
SUFFIX = ""
92+
}
93+
steps {
94+
dir("src/${PROJ}") {
95+< 9C9A /span>
sh """
96+
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+
cd build/\${GOOS}_\${GOARCH}
98+
zip ../../target/dist/\${GOOS}_\${GOARCH}.zip tech-db-forum\${SUFFIX}
99+
"""
100+
}
101+
}
102+
}
103+
stage('windows_386') {
104+
environment {
105+
GOOS = "windows"
106+
GOARCH = "386"
107+
SUFFIX = ".exe"
108+
}
109+
steps {
110+
dir("src/${PROJ}") {
111+
sh """
112+
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+
cd build/\${GOOS}_\${GOARCH}
114+
zip ../../target/dist/\${GOOS}_\${GOARCH}.zip tech-db-forum\${SUFFIX}
115+
"""
116+
}
117+
}
118+
}
119+
stage('windows_amd64') {
120+
environment {
121+
GOOS = "windows"
122+
GOARCH = "amd64"
123+
SUFFIX = ".exe"
124+
}
125+
steps {
126+
dir("src/${PROJ}") {
127+
sh """
128+
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+
cd build/\${GOOS}_\${GOARCH}
130+
zip ../../target/dist/\${GOOS}_\${GOARCH}.zip tech-db-forum\${SUFFIX}
131+
"""
132+
}
133+
}
134+
}
135+
}
136+
}
137+
stage('Prepare gp-pages') {
138+
steps {
139+
dir("src/${PROJ}") {
140+
sh """
60141
git branch -fD gh-pages || true
61142
git branch -rd origin/gh-pages || true
62143
ghp-import -n target/dist
63144
"""
64-
archive "src/$goProject/target/dist/*.zip"
65-
}
66-
if (env.BRANCH_NAME == 'master') {
67-
stage ('Publish') {
68-
withCredentials([usernamePassword(credentialsId: '88e000b8-d989-4f94-b919-1cc1352a5f96', passwordVariable: 'TOKEN', usernameVariable: 'LOGIN')]) {
69-
sh """
70-
cd src/$goProject
145+
}
146+
}
147+
}
148+
stage('Publish gh-pages') {
149+
when {
150+
branch 'master'
151+
}
152+
steps {
153+
withCredentials([usernamePassword(credentialsId: '88e000b8-d989-4f94-b919-1cc1352a5f96', passwordVariable: 'TOKEN', usernameVariable: 'LOGIN')]) {
154+
dir("src/${PROJ}") {
155+
sh """
71156
git push -qf https://\${TOKEN}@github.com/bozaro/tech-db-forum.git gh-pages
72157
"""
73-
}
74-
}
75-
}
76-
if (params.TAG_NAME != "") {
77-
stage ("Publish: github") {
78-
withEnv([
79-
"TAG_NAME=${params.TAG_NAME}",
80-
"GITHUB_USER=bozaro",
81-
"GITHUB_REPO=tech-db-forum",
82-
]) {
83-
withCredentials([[$class: 'StringBinding', credentialsId: '49bf22be-f4d4-4a75-855a-b0e56e357f1c', variable: 'GITHUB_TOKEN']]) {
84-
sh """
85-
export GOPATH="\$PWD"
86-
export PATH="\$GOPATH/bin:\$PATH"
87-
88-
github-release info --tag \$TAG_NAME || github-release release --tag \$TAG_NAME --draft
89-
for i in src/$goProject/target/dist/*.zip; do
90-
github-release upload --tag \$TAG_NAME --file \$i --name `basename \$i`
158+
}
159+
}
160+
}
161+
}
162+
stage('Publish release') {
163+
when {
164+
expression { params.TAG_NAME != "" }
165+
}
166+
environment {
167+
GITHUB_USER = "bozaro"
168+
GITHUB_REPO = "tech-db-forum"
169+
}
170+
steps {
171+
withCredentials([[$class: 'StringBinding', credentialsId: '49bf22be-f4d4-4a75-855a-b0e56e357f1c', variable: 'GITHUB_TOKEN']]) {
172+
dir("src/${PROJ}") {
17 5C7A 3+
sh """
174+
github-release info --tag ${params.TAG_NAME} || github-release release --tag ${params.TAG_NAME} --draft
175+
for i in target/dist/*.zip; do
176+
github-release upload --tag ${params.TAG_NAME} --file \$i --name `basename \$i`
91177
done
92178
"""
179+
}
180+
}
181+
}
182+
}
183+
}
184+
post {
185+
always {
186+
archiveArtifacts artifacts: "src/${PROJ}/target/dist/*.zip", fingerprint: true
93187
}
94-
}
95188
}
96-
}
97189
}

0 commit comments

Comments
 (0)
0