-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
78 lines (75 loc) · 1.92 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
78
pipeline {
agent {
kubernetes {
label 'build-pod'
defaultContainer 'jnlp'
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: docker
image: docker:stable
command:
- cat
tty: true
volumeMounts:
- name: docker-sock
mountPath: /var/run/docker.sock
- name: k8s-deploy
image: rogaha/k8s-deploy
command:
- cat
tty: true
volumes:
- name: docker-sock
hostPath:
path: /var/run/docker.sock
"""
}
}
environment {
DOCKERHUB_CREDENTIALS = credentials('dockerhub_credentials')
DOCKER_REPOSITORY = 'rogaha'
APP_NAME = 'hello-nginx'
HELM_RELEASE_NAME = 'dockercon-demo'
}
stages {
stage('Build') {
steps {
script {
imageTag = imageTag()
imageName = "${DOCKERHUB_CREDENTIALS_USR}/${APP_NAME}:${imageTag}"
}
container('docker') {
sh "docker build -t ${imageName} hello-nginx"
}
}
}
stage('Publish') {
steps {
container('docker') {
sh "echo ${DOCKERHUB_CREDENTIALS_PSW}" +
" | docker login -u ${DOCKERHUB_CREDENTIALS_USR} --password-stdin"
sh "docker push ${imageName}"
}
}
}
stage('Deploy') {
steps {
container('k8s-deploy') {
sh "helm upgrade -i" +
" --namespace jenkins" +
" --set image.tag=${imageTag}" +
" ${APP_NAME} charts/${APP_NAME}"
}
}
}
}
}
def imageTag() {
sh 'git rev-parse --short HEAD > commit-id'
return readFile('commit-id')
.replace('\n', '')
.replace('\r', '')
}