-
Notifications
You must be signed in to change notification settings - Fork 32
/
Jenkinsfile
151 lines (148 loc) · 4.87 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
pipeline {
agent {
dockerfile {
filename 'Dockerfile.build'
customWorkspace "workspace/tech-db-forum"
}
}
parameters {
string(name: 'TAG_NAME', defaultValue: '', description: 'Tag name')
}
environment {
PROJ = "github.com/bozaro/tech-db-forum"
}
stages {
stage('Prepare') {
steps {
sh """
export GOPATH=\$HOME/go
export PATH=\$GOPATH/bin:\$PATH
go install -v github.com/go-swagger/go-swagger/cmd/swagger
go install -v github.com/jteeuwen/go-bindata/go-bindata
go install -v github.com/mailru/easyjson/easyjson
go install -v github.com/aktau/github-release
go generate -x .
mkdir -p target/dist
"""
}
}
stage('Build') {
failFast true
parallel {
stage('darwin_amd64') {
environment {
GOOS = "darwin"
GOARCH = "amd64"
SUFFIX = ""
}
steps {
sh """
export GOPATH=\$HOME/go
export PATH=\$GOPATH/bin:\$PATH
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}
cd build/\${GOOS}_\${GOARCH}
zip ../../target/dist/\${GOOS}_\${GOARCH}.zip tech-db-forum\${SUFFIX}
"""
}
}
stage('linux_amd64') {
environment {
GOOS = "linux"
GOARCH = "amd64"
SUFFIX = ""
}
steps {
sh """
export GOPATH=\$HOME/go
export PATH=\$GOPATH/bin:\$PATH
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}
cd build/\${GOOS}_\${GOARCH}
zip ../../target/dist/\${GOOS}_\${GOARCH}.zip tech-db-forum\${SUFFIX}
"""
}
}
stage('windows_386') {
environment {
GOOS = "windows"
GOARCH = "386"
SUFFIX = ".exe"
}
steps {
sh """
export GOPATH=\$HOME/go
export PATH=\$GOPATH/bin:\$PATH
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}
cd build/\${GOOS}_\${GOARCH}
zip ../../target/dist/\${GOOS}_\${GOARCH}.zip tech-db-forum\${SUFFIX}
"""
}
}
stage('windows_amd64') {
environment {
GOOS = "windows"
GOARCH = "amd64"
SUFFIX = ".exe"
}
steps {
sh """
export GOPATH=\$HOME/go
export PATH=\$GOPATH/bin:\$PATH
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}
cd build/\${GOOS}_\${GOARCH}
zip ../../target/dist/\${GOOS}_\${GOARCH}.zip tech-db-forum\${SUFFIX}
"""
}
}
}
}
stage('Prepare gp-pages') {
steps {
sh """
git branch -fD gh-pages || true
git branch -rd origin/gh-pages || true
ghp-import -n target/dist
"""
}
}
stage('Publish gh-pages') {
when {
branch 'master'
}
steps {
withCredentials([[$class: 'StringBinding', credentialsId: 'github_bozaro', variable: 'GITHUB_TOKEN']]) {
sh """
git push -qf https://\${GITHUB_TOKEN}@github.com/bozaro/tech-db-forum.git gh-pages
"""
}
}
}
stage('Publish release') {
when {
expression { params.TAG_NAME != "" }
}
environment {
GITHUB_USER = "bozaro"
GITHUB_REPO = "tech-db-forum"
}
steps {
withCredentials([[$class: 'StringBinding', credentialsId: 'github_bozaro', variable: 'GITHUB_TOKEN']]) {
sh """
export GOPATH=\$HOME/go
export PATH=\$GOPATH/bin:\$PATH
github-release info --tag ${params.TAG_NAME} || github-release release --tag ${params.TAG_NAME} --draft
for i in target/dist/*.zip; do
github-release upload --tag ${params.TAG_NAME} --file \$i --name `basename \$i`
done
git tag ${params.TAG_NAME}
git push -qf https://\${GITHUB_TOKEN}@github.com/bozaro/tech-db-forum.git gh-pages ${params.TAG_NAME}
"""
}
}
}
}
post {
always {
archiveArtifacts artifacts: "target/dist/*.zip", fingerprint: true
}
}
}