E58A Jenkins with docker · bozaro/tech-db-forum@0535d57 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0535d57

Browse files
committed
Jenkins with docker
1 parent b29d3fe commit 0535d57

File tree

2 files changed

+34
-70
lines changed

2 files changed

+34
-70
lines changed

Dockerfile.build

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM ubuntu:18.04
2+
3+
RUN apt update
4+
RUN apt install -y zip golang-go ghp-import git python-pkg-resources
5+
6+
ENV HOME=/var/jenkins_home

Jenkinsfile

Lines changed: 28 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,33 @@
1-
/*
2-
sudo apt install ghp-import
3-
*/
41
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+
}
137
}
148

159
parameters {
1610
string(name: 'TAG_NAME', defaultValue: '', description: 'Tag name')
1711
}
1812

1913
environment {
20-
GOPATH = "$WORKSPACE"
14+
HOME = "/var/jenkins_home"
2115
PROJ = "github.com/bozaro/tech-db-forum"
22-
PATH = "$GOPATH/bin:$PATH"
16+
GOPATH = "/var/jenkins_home/go"
2317
}
2418

2519
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-
}
3620
stage('Prepare') {
3721
steps {
38-
dir("src/${PROJ}") {
39-
sh """
22+
sh """
23+
export PATH=\$GOPATH/bin:\$PATH
4024
go install -v ./vendor/github.com/go-swagger/go-swagger/cmd/swagger
4125
go install -v ./vendor/github.com/jteeuwen/go-bindata/go-bindata
4226
go install -v ./vendor/github.com/mailru/easyjson/easyjson
4327
go install -v ./vendor/github.com/aktau/github-release
4428
go generate -x .
29+
mkdir -p target/dist
4530
"""
46-
}
47-
dir("src/${PROJ}/target/dist") {
48-
sh "true"
49-
}
5031
}
5132
}
5233
stage('Build') {
@@ -59,29 +40,12 @@ go generate -x .
5940
SUFFIX = ""
6041
}
6142
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
8045
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}
8146
cd build/\${GOOS}_\${GOARCH}
8247
zip ../../target/dist/\${GOOS}_\${GOARCH}.zip tech-db-forum\${SUFFIX}
8348
"""
84-
}
8549
}
8650
}
8751
stage('linux_amd64') {
@@ -91,13 +55,12 @@ zip ../../target/dist/\${GOOS}_\${GOARCH}.zip tech-db-forum\${SUFFIX}
9155
SUFFIX = ""
9256
}
9357
steps {
94-
dir("src/${PROJ}") {
95-
sh """
58+
sh """
59+
export PATH=\$GOPATH/bin:\$PATH
9660
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}
9761
cd build/\${GOOS}_\${GOARCH}
9862
zip ../../target/dist/\${GOOS}_\${GOARCH}.zip tech-db-forum\${SUFFIX}
9963
"""
100-
}
10164
}
10265
}
10366
stage('windows_386') {
@@ -107,13 +70,12 @@ zip ../../target/dist/\${GOOS}_\${GOARCH}.zip tech-db-forum\${SUFFIX}
10770
SUFFIX = ".exe"
10871
}
10972
steps {
110-
dir("src/${PROJ}") {
111-
sh """
73+
sh """
74+
export PATH=\$GOPATH/bin:\$PATH
11275
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}
11376
cd build/\${GOOS}_\${GOARCH}
11477
zip ../../target/dist/\${GOOS}_\${GOARCH}.zip tech-db-forum\${SUFFIX}
11578
"""
116-
}
11779
}
11880
}
11981
stage('windows_amd64') {
@@ -123,39 +85,34 @@ zip ../../target/dist/\${GOOS}_\${GOARCH}.zip tech-db-forum\${SUFFIX}
12385
SUFFIX = ".exe"
12486
}
12587
steps {
126-
dir("src/${PROJ}") {
127-
sh """
88+
sh """
89+
export PATH=\$GOPATH/bin:\$PATH
12890
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}
12991
cd build/\${GOOS}_\${GOARCH}
13092
zip ../../target/dist/\${GOOS}_\${GOARCH}.zip tech-db-forum\${SUFFIX}
13193
"""
132-
}
13394
}
13495
}
13596
}
13697
}
13798
stage('Prepare gp-pages') {
13899
steps {
139-
dir("src/${PROJ}") {
140-
sh """
100+
sh """
141101
g 5B9E it branch -fD gh-pages || true
142102
git branch -rd origin/gh-pages || true
143103
ghp-import -n target/dist
144104
"""
145-
}
146105
}
147106
}
148107
stage('Publish gh-pages') {
149108
when {
150109
branch 'master'
151110
}
152111
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
157115
"""
158-
}
159116
}
160117
}
161118
}
@@ -168,22 +125,23 @@ git push -qf https://\${TOKEN}@github.com/bozaro/tech-db-forum.git gh-pages
168125
GITHUB_REPO = "tech-db-forum"
169126
}
170127
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
174131
github-release info --tag ${params.TAG_NAME} || github-release release --tag ${params.TAG_NAME} --draft
175132
for i in target/dist/*.zip; do
176133
github-release upload --tag ${params.TAG_NAME} --file \$i --name `basename \$i`
177134
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}
178137
"""
179-
}
180138
}
181139
}
182140
}
183141
}
184142
post {
185143
always {
186-
archiveArtifacts artifacts: "src/${PROJ}/target/dist/*.zip", fingerprint: true
144+
archiveArtifacts artifacts: "target/dist/*.zip", fingerprint: true
187145
}
188146
}
189147
}

0 commit comments

Comments
 (0)
0