-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJenkinsfile
49 lines (44 loc) · 1.15 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
pipeline {
agent any
environment {
imageName = 'registry.gigasource.io/pos-vue-framework'
image = ''
registryName = 'https://registry.gigasource.io'
registryCredential = 'registry-user'
rancherDeploymentName = 'pos-vue-framework'
}
stages {
stage('Build Docker image') {
steps {
script {
CURRENT_DATETIME = sh (
script: "date +%Y-%m-%d_%Hh.%Mm.%Ss",
returnStdout: true
).trim()
}
script {image = docker.build imageName + ":$CURRENT_DATETIME"}
}
}
stage('Push Docker image to registry') {
steps {
script {
docker.withRegistry(registryName, registryCredential ) {
image.push()
}
}
}
}
stage('Remove locally built Docker image') {
steps {
sh "docker rmi $imageName:$CURRENT_DATETIME"
}
}
stage('Upgrade image version in Rancher') {
steps {
withKubeConfig([credentialsId: 'kubectl-config']) {
sh "kubectl set image deployment/$rancherDeploymentName $rancherDeploymentName=$imageName:$CURRENT_DATETIME --record"
}
}
}
}
}