forked from spring-projects/spring-petclinic
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
92 lines (83 loc) · 2.97 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
pipeline {
agent {
label 'master'
}
stages {
stage('init') {
steps {
git url: "[email protected]:azure-devops/spring-petclinic.git",
credentialsId: "github_ssh_key",
branch: "ignite"
script {
env.SHA = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
env.GIT_TAG = sh(script: 'git tag -l --points-at HEAD', returnStdout: true).trim()
if (env.GIT_TAG == '') {
env.IMAGE_TAG = SHA
env.DEPLOY_TO = "staging"
} else {
env.IMAGE_TAG = env.GIT_TAG
env.DEPLOY_TO = "production"
}
}
}
}
stage('build') {
when {
changeset "src/**"
}
steps {
sh '''
./mvnw clean package
mv target/*.jar target/pet-clinic.jar
'''
}
}
stage('image build') {
when {
changeset "src/**"
}
steps {
acrQuickTask azureCredentialsId: "jenkins-sp",
registryName: "jenkinsdemosacr",
resourceGroupName: "demo-aks",
local: "",
dockerfile: "Dockerfile",
imageNames: [[image: "jenkinsdemosacr.azurecr.io/pet-clinic:pc-${IMAGE_TAG}"]]
}
}
stage('update staging config') {
when {
changeset "src/**"
environment name: "DEPLOY_TO", value: 'staging'
}
steps {
dir('infra/kube/workloads/staging') {
sh '''
sed -i -e "s/pc-......./pc-\${IMAGE_TAG}/" deployment.yaml
sed -i -e "s/pc-......./pc-\${IMAGE_TAG}/" service.yaml
git add *
git commit -m "Update staging config with \${IMAGE_TAG} commit"
git push origin ignite
'''
}
}
}
stage('update production config') {
when {
changeset "src/*"
environment name: "DEPLOY_TO", value: 'production'
}
steps {
dir('infra/kube/workloads/production') {
sh '''
sed -i -e "s/v[0-9]\\.[0-9]\\.[0-9]/\${IMAGE_TAG}/" deployment.yaml
sed -i -e "s/v[0-9]\\.[0-9]\\.[0-9]/\${IMAGE_TAG}/" service.yaml
git add *
git commit -m "Update production config with \${IMAGE_TAG} commit"
git push origin ignite
'''
}
}
}
}
}