-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
51 lines (48 loc) · 1.47 KB
/
Jenkinsfile
File metadata and controls
51 lines (48 loc) · 1.47 KB
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
/**
* This pipeline will run a Docker image build
*/
def label = "docker-${UUID.randomUUID().toString()}"
podTemplate(label: label, containers: [
containerTemplate(
name: 'docker',
image: 'docker',
command: 'cat',
ttyEnabled: true
),
containerTemplate(
name: 'kubectl',
image: 'lachlanevenson/k8s-kubectl',
command: 'cat',
ttyEnabled: true
)],
volumes: [
hostPathVolume(
mountPath: '/var/run/docker.sock',
hostPath: '/var/run/docker.sock',
)
]
) {
registry = "ivelia/jenkins-k8s"
registryCredential = "ivelia"
dockerImage = ''
node(label) {
stage('Build Docker image and push to docker registry') {
git 'https://github.com/Nkoli/jenkins-kubernetes-deployment.git'
container('docker') {
script {
dockerImage = docker.build registry + ":$BUILD_NUMBER"
docker.withRegistry( '', registryCredential ) {
dockerImage.push()
}
}
}
}
stage('Kubernetes Deployment') {
container('kubectl') {
sh "sed -i 's/image:\\s*ivelia\\/jenkins-k8s/image: ivelia\\/jenkins-k8s:${BUILD_NUMBER}/g' ${WORKSPACE}/deployment.yaml"
sh "kubectl apply -f ${WORKSPACE}/deployment.yaml"
sh "kubectl apply -f service.yaml"
}
}
}
}