-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathJenkinsfile
48 lines (46 loc) · 1.95 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
podTemplate(label: 'mynode',
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: 'kubectl', image: 'lachlanevenson/k8s-kubectl', ttyEnabled: true, command: 'cat'),
containerTemplate(name: 'docker' , image: 'docker:17.06.1-ce', ttyEnabled: true, command: 'cat')
]){
node('mynode') {
checkout scm
container('docker') {
stage('build app') {
sh """
#!/bin/bash
cd src
npm install
ng build
"""
}
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}/greenapp:${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}/greenapp:${env.BUILD_NUMBER}
"""
}
}
}
}