-
Notifications
You must be signed in to change notification settings - Fork 13
/
Jenkinsfile
43 lines (38 loc) · 1.55 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
#!groovy
properties([
buildDiscarder(logRotator(daysToKeepStr: '20', numToKeepStr: '30', artifactNumToKeepStr: '3')),
copyArtifactPermission('*'),
pipelineTriggers([
pollSCM('H/15 * * * *'),
githubPush(),
]),
parameters([
booleanParam(name: 'ARCHIVE_ARTIFACTS', defaultValue: true),
booleanParam(name: 'CLEAN', defaultValue: true)
])
])
node('amd64 && docker') {
try {
stage('SCM') {
checkout scm
}
stage('Build') {
sh "docker run --rm -e CGO_ENABLED=0 -e GOARCH=arm64 -e GOCACHE=/usr/src/myapp/cache -u \"\$(id -u):\$(id -g)\" -v /etc/passwd:/etc/passwd:ro -v /etc/group:/etc/group:ro -v \"\$PWD\":/usr/src/myapp -w /usr/src/myapp golang:1.19 ./build"
sh "mv bin bin.arm64"
sh "docker run --rm -e CGO_ENABLED=1 -e GOARCH=amd64 -e GOCACHE=/usr/src/myapp/cache -u \"\$(id -u):\$(id -g)\" -v /etc/passwd:/etc/passwd:ro -v /etc/group:/etc/group:ro -v \"\$PWD\":/usr/src/myapp -w /usr/src/myapp golang:1.19 ./build"
}
stage('Test') {
sh 'docker run --rm -e GOCACHE=/usr/src/myapp/cache -u "$(id -u):$(id -g)" -v /etc/passwd:/etc/passwd:ro -v /etc/group:/etc/group:ro -v "$PWD":/usr/src/myapp -w /usr/src/myapp golang:1.19 ./test'
}
stage('Post-build') {
if (env.JOB_BASE_NAME == "master-builder" || params.ARCHIVE_ARTIFACTS) {
archiveArtifacts artifacts: 'bin/**, bin.arm64/**', fingerprint: true, onlyIfSuccessful: true
}
}
} finally {
if (params.CLEAN) {
sh 'sudo chown -R $USER .'
cleanWs()
}
}
}