forked from caicloud/canary-release
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
97 lines (93 loc) · 3.31 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
def REGISTRY = "cargo.caicloudprivatetest.com"
def version = "${params.imageTag}"
podTemplate(
cloud: 'dev-cluster',
namespace: 'kube-system',
name: 'canary-release',
// change the label to your component name.
label: 'canary-release',
containers: [
// a Jenkins agent (FKA "slave") using JNLP to establish connection.
containerTemplate(
name: 'jnlp',
// alwaysPullImage: true,
image: 'cargo.caicloudprivatetest.com/caicloud/jenkins/jnlp-slave:3.14-1-alpine',
command: '',
args: '${computer.jnlpmac} ${computer.name}',
),
// docker in docker
containerTemplate(
name: 'dind',
image: 'cargo.caicloudprivatetest.com/caicloud/docker:17.09-dind',
ttyEnabled: true,
command: '',
args: '--host=unix:///home/jenkins/docker.sock',
privileged: true,
),
// golang with docker client and tools
containerTemplate(
name: 'golang',
image: 'cargo.caicloudprivatetest.com/caicloud/golang-docker:1.9-17.09',
ttyEnabled: true,
command: '',
args: '',
envVars: [
containerEnvVar(key: 'DOCKER_HOST', value: 'unix:///home/jenkins/docker.sock'),
// Change the environment variable WORKDIR as needed.
containerEnvVar(key: 'WORKDIR', value: '/go/src/github.com/caicloud/canary-release'),
containerEnvVar(key: 'GO_BUILD_PLATFORMS', value: "linux/amd64"),
containerEnvVar(key: 'PRJ_GIT_VERSION', value: "${version}"),
containerEnvVar(key: 'REGISTRIES', value: "${REGISTRY}"+"/caicloud")
],
)
]
) {
// Change the node name as the podTemplate label you set.
node('canary-release') {
stage('Checkout') {
checkout scm
}
// Change the container name as the container you use for compiling.
container('golang') {
ansiColor('xterm') {
stage("Prepare Project") {
sh('''
set -e
mkdir -p $(dirname ${WORKDIR})
rm -rf ${WORKDIR}
cp -r $(pwd) ${WORKDIR}
''')
}
// You can define the stage as you need.
stage('Unit test') {
sh('''
set -e
cd ${WORKDIR}
make unittest
''')
}
stage("Complie") {
sh('''
set -e
cd ${WORKDIR}
make build
''')
}
stage('Build and push image') {
docker.withRegistry("https://${REGISTRY}", "cargo-private-admin") {
sh('''
cd ${WORKDIR}
make container
''')
if (params.publish) {
sh('''
cd ${WORKDIR}
make push
''')
}
}
}
}
}
}
}