/
build.Jenkinsfile
51 lines (45 loc) · 1.38 KB
/
build.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
//
//
label = "bad-actor-services-web-data-${env.BUILD_NUMBER}"
Image = "politeauthority/carpetbag"
podTemplate(
label: label,
name: "jenkins-" + label,
cloud: "kubernetes",
containers:
[
containerTemplate(
image: 'docker',
name: 'docker',
ttyEnabled: true,
command: 'cat',
envVars: [],
alwaysPullImage: false
)
],
volumes: [
hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock'),
]
) {
node(label) {
checkout scm
container('docker') {
stage('Build Image') {
sh """
docker build -t carpetbag --no-cache .
"""
}
stage('Push Image') {
withCredentials([usernamePassword(credentialsId: 'dockerhub', usernameVariable: 'Username', passwordVariable: 'Password')]) {
sh """
docker login -u politeauthority -p $Password
docker tag carpetbag ${Image}:latest
docker push ${Image}:latest
docker tag carpetbag${Image}:${env.BUILD_NUMBER}
docker push ${Image}:${env.BUILD_NUMBER}
"""
}
}
}
}
}