-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathJenkinsfile
58 lines (58 loc) · 1.75 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
podTemplate(
label: 'mypod',
inheritFrom: 'default',
containers: [
containerTemplate(
name: 'golang',
image: 'golang:1.10-alpine',
ttyEnabled: true,
command: 'cat'
),
containerTemplate(
name: 'docker',
image: 'docker:18.02',
ttyEnabled: true,
command: 'cat'
),
containerTemplate(
name: 'helm',
image: 'ibmcom/k8s-helm:v2.6.0',
ttyEnabled: true,
command: 'cat'
)
],
volumes: [
hostPathVolume(
hostPath: '/var/run/docker.sock',
mountPath: '/var/run/docker.sock'
)
]
) {
node('mypod') {
def commitId
stage ('Extract') {
checkout scm
commitId = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
}
stage ('Build') {
container ('golang') {
sh 'CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .'
}
}
def repository
stage ('Docker') {
container ('docker') {
def registryIp = sh(script: 'getent hosts registry.kube-system | awk \'{ print $1 ; exit }\'', returnStdout: true).trim()
repository = "${registryIp}:80/hello"
sh "docker build -t ${repository}:${commitId} ."
sh "docker push ${repository}:${commitId}"
}
}
stage ('Deploy') {
container ('helm') {
sh "/helm init --client-only --skip-refresh"
sh "/helm upgrade --install --wait --set image.repository=${repository},image.tag=${commitId} hello hello"
}
}
}
}