forked from caicloud/rudder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
102 lines (82 loc) · 3.01 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
def releaseImage = "caicloud/rudder:${params.imageTag}"
podTemplate(
cloud: 'dev-cluster',
namespace: 'kube-system',
// change the label to your component name.
label: 'rudder',
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/rudder')
],
)
]
) {
// Change the node name as the podTemplate label you set.
node('rudder') {
stage('Checkout') {
checkout scm
}
// Change the container name as the container you use for compiling.
container('golang') {
ansiColor('xterm') {
// You can define the stage as you need.
stage("Complie") {
sh('''
set -e
mkdir -p $(dirname ${WORKDIR})
rm -rf ${WORKDIR}
ln -sfv $(pwd) ${WORKDIR}
cd ${WORKDIR}
make build
''')
}
stage('Unit test') {
sh('''
set -e
cd ${WORKDIR}
make test
''')
}
stage('Build and push image') {
sh('''
set -e
cd ${WORKDIR}
''')
sh("docker build -t ${releaseImage} -f build/release/Dockerfile .")
// Whether publish the images is controlled by the params.
if (params.publish) {
docker.withRegistry("https://cargo.caicloudprivatetest.com", "cargo-private-admin") {
docker.image(releaseImage).push()
}
}
}
}
}
}
}