-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
77 lines (62 loc) · 2.85 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: 'mypod', containers: [
containerTemplate(name: 'docker', image: 'docker', ttyEnabled: true, command: 'cat'),
containerTemplate(name: 'kubectl', image: 'lachlanevenson/k8s-kubectl:v1.8.0', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'helm', image: 'lachlanevenson/k8s-helm:latest', command: 'cat', ttyEnabled: true)
],
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
]) {
node('mypod') {
stage 'Build docker image'
container('docker') {
// Store these credentials in Jenkins too
withCredentials([[$class: 'UsernamePasswordMultiBinding',
credentialsId: 'e7de4146-4a59-4406-916e-d10506cfaeb8',
usernameVariable: 'DOCKER_HUB_USER',
passwordVariable: 'DOCKER_HUB_PASSWORD']]) {
sh """
docker build -t ${imageTag} /src/main/docker
"""
}
}
stage 'Push image to the registry'
container('docker') {
// Store these credentials in Jenkins too
withCredentials([[$class: 'UsernamePasswordMultiBinding',
credentialsId: 'e7de4146-4a59-4406-916e-d10506cfaeb8',
usernameVariable: 'DOCKER_HUB_USER',
passwordVariable: 'DOCKER_HUB_PASSWORD']]) {
sh """
docker login -u ${env.DOCKER_HUB_USER} -p ${env.DOCKER_HUB_PASSWORD}
docker push ${imageTag}
"""
}
}
stage('do some Docker work') {
container('docker') {
withCredentials([[$class: 'UsernamePasswordMultiBinding',
credentialsId: 'e7de4146-4a59-4406-916e-d10506cfaeb8',
usernameVariable: 'DOCKER_HUB_USER',
passwordVariable: 'DOCKER_HUB_PASSWORD']]) {
sh """
docker pull ubuntu
docker tag ubuntu ${env.DOCKER_HUB_USER}/ubuntu:${env.BUILD_NUMBER}
"""
sh "docker login -u ${env.DOCKER_HUB_USER} -p ${env.DOCKER_HUB_PASSWORD} "
sh "docker push ${env.DOCKER_HUB_USER}/ubuntu:${env.BUILD_NUMBER} "
}
}
}
stage('do some kubectl work') {
container('kubectl') {
withCredentials([[
$class: 'FileBinding',
credentialsId: '77bd756d-382a-4704-bb9c-9d52f023ac4d',
variable: 'KUBECONFIG'
]]){
sh("kubectl --kubeconfig=$KUBECONFIG --namespace={{APP_NAMESPACE}} get nodes")
}
}
}
}
}