-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
77 lines (68 loc) · 3.28 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
podTemplate(label: 'buildpod',
volumes: [
hostPathVolume(hostPath: '/etc/docker/certs.d', mountPath: '/etc/docker/certs.d'),
hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock'),
secretVolume(secretName: 'registry-account', mountPath: '/var/run/secrets/registry-account'),
configMapVolume(configMapName: 'registry-config', mountPath: '/var/run/configs/registry-config')
],
containers: [
containerTemplate(name: 'docker', image: 'wizplaycluster.icp:8500/default/docker:latest', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'containertest', image: 'wizplaycluster.icp:8500/default/containertest:latest', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'helm', image: 'wizplaycluster.icp:8500/default/k8s-helm:latest', command: 'cat', ttyEnabled: true)
]) {
node('buildpod') {
checkout scm
container('docker') {
stage('Build Docker Image') {
sh """
#!/bin/bash
NAMESPACE=`cat /var/run/configs/registry-config/namespace`
REGISTRY=`cat /var/run/configs/registry-config/registry`
docker build -t \${REGISTRY}/\${NAMESPACE}/hello-container:${env.BUILD_NUMBER} .
"""
}
stage('Push Docker Image to Registry') {
sh """
#!/bin/bash
NAMESPACE=`cat /var/run/configs/registry-config/namespace`
REGISTRY=`cat /var/run/configs/registry-config/registry`
set +x
DOCKER_USER=`cat /var/run/secrets/registry-account/username`
DOCKER_PASSWORD=`cat /var/run/secrets/registry-account/password`
docker login -u=\${DOCKER_USER} -p=\${DOCKER_PASSWORD} \${REGISTRY}
set -x
docker push \${REGISTRY}/\${NAMESPACE}/hello-container:${env.BUILD_NUMBER}
"""
}
}
container('containertest') {
stage('Test built docker Image') {
sh """
#!/bin/bash
NAMESPACE=`cat /var/run/configs/registry-config/namespace`
REGISTRY=`cat /var/run/configs/registry-config/registry`
container-structure-test -test.v -image \${REGISTRY}/\${NAMESPACE}/hello-container:${env.BUILD_NUMBER} /var/tmp/hello-container-test.yaml
"""
}
}
container('helm') {
stage('Deploy new helm release') {
sh """
#!/bin/bash
set +e
NAMESPACE=`cat /var/run/configs/registry-config/namespace`
REGISTRY=`cat /var/run/configs/registry-config/registry`
CHARTNAME=`helm list --deployed --short hello-container`
helm list \${CHARTNAME}
if [ \${?} -ne "0" ]; then
# No chart release to update
echo 'No chart release to update'
exit 1
fi
# Update Release
helm upgrade hello-container ./hellocontainer-chart/ --set image.repository=\${REGISTRY}/\${NAMESPACE}/hello-container --set image.tag=${env.BUILD_NUMBER}
"""
}
}
}
}