-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
47 lines (47 loc) · 1.48 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
pipeline {
agent any
environment {
COMMIT = (sh (script: "git rev-parse --short HEAD", returnStdout: true)).trim()
}
stages {
stage('Build') {
steps {
sh '''
docker image build . \
-t "tekkengod129/weather:latest" \
-t "tekkengod129/weather:${COMMIT}"
'''
}
}
stage('Push') {
steps {
withCredentials([
usernamePassword(
usernameVariable: 'DOCKERHUB_USERNAME',
passwordVariable: 'DOCKERHUB_PASSWORD',
credentialsId: 'dockerhub'
)
]) {
sh '''
docker login --username $DOCKERHUB_USERNAME --password $DOCKERHUB_PASSWORD
docker push tekkengod129/weather:${COMMIT}
docker push tekkengod129/weather:latest
'''
}
}
}
stage('Deploy to K8s') {
steps {
withKubeConfig([credentialsId: 'kubernetes-token', serverUrl: 'https://weather.p5.do-school.ru:6443']) {
sh 'kubectl set image deployments/weather-deployment weather=tekkengod129/weather:${COMMIT}'
}
}
}
}
post {
always {
sh 'docker logout'
cleanWs()
}
}
}