-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
176 lines (167 loc) · 6.66 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
pipeline {
agent {
kubernetes {
yaml '''
apiVersion: v1
kind: Pod
spec:
containers:
-
name: argo
image: 'docker.generalmills.com/k8s-argocli:stable'
command:
- cat
tty: true
'''
}
}
environment {
PROJECT_NAME = 'trade-cars'
IMAGE_REGISTRY = 'docker.generalmills.com'
GIT_COMMIT_SHORT = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
CLEAN_BRANCH_NAME = "${env.BRANCH_NAME.toLowerCase().replaceAll(/[^a-z0-9-]+/,'-')}"
}
stages {
stage('Setup') {
steps {
beginBuild()
updatePullRequestStatus state: 'pending'
}
}
stage('Build') {
agent { label 'linux' }
steps {
script {
env.BUILD_TAG = "$BUILD_NUMBER-$GIT_COMMIT_SHORT"
env.ORIGINAL_BUILD_NUMBER = "$BUILD_NUMBER"
}
sh 'docker build . -t $IMAGE_REGISTRY/docker-snapshot-local/$PROJECT_NAME:$BUILD_TAG --build-arg branch_build_commit="$CLEAN_BRANCH_NAME $BUILD_NUMBER $GIT_COMMIT_SHORT"'
pushToArtifactoryContainerImage image: "$PROJECT_NAME", tag: "$BUILD_TAG", registry: "$IMAGE_REGISTRY"
scanBuild buildName: "$PROJECT_NAME", buildNumber: "$BUILD_TAG"
}
}
stage('Deploy dev/alpha/stable') {
environment {
// master goes to "dev", a release branch to "stable", the rest to "alpha"
HOST_ENVIRONMENT = "${CLEAN_BRANCH_NAME == "master" ? "development" : CLEAN_BRANCH_NAME ==~ /release-.*/ ? "stable" : "alpha"}"
SUBDOMAIN_SUFFIX = "${HOST_ENVIRONMENT == "development" ? "dev" : HOST_ENVIRONMENT}"
HOST = "${PROJECT_NAME}-${SUBDOMAIN_SUFFIX}.k8s.genmills.com"
}
steps {
echo "Attempting deploy via Argo for a host at https://${HOST} with ASPNETCORE_ENVIRONMENT=${HOST_ENVIRONMENT}"
container('argo') {
deployK8sApplicationV2 cluster_env: 'nonprod', app_env: env.SUBDOMAIN_SUFFIX, extra_args:[
helm: [
releaseName: env.PROJECT_NAME,
values: [
image: [
"repository": "${IMAGE_REGISTRY}/${PROJECT_NAME}",
"tag": "$BUILD_TAG",
],
istio: [
hosts: [env.HOST],
],
extraEnvs: [ "ASPNETCORE_ENVIRONMENT": env.HOST_ENVIRONMENT ]
],
],
]
}
echo "Site was deployed to a host at https://${HOST}"
}
}
stage('Deploy to QA?') {
agent none
when { anyOf { branch 'release-*'; branch 'master' } }
steps {
script {
safeInput message: 'Deploy to QA?',
timeout: 30,
timeoutUnit: 'MINUTES',
submitter: 'DEPLOY_QA_TRADEUS_PARAGON'
}
}
}
stage('Deploy QA') {
when { anyOf { branch 'release-*'; branch 'master' } }
environment {
HOST_ENVIRONMENT = "qa"
SUBDOMAIN_SUFFIX = "${HOST_ENVIRONMENT}"
HOST = "${PROJECT_NAME}-${SUBDOMAIN_SUFFIX}.k8s.genmills.com"
}
steps {
echo "Attempting deploy via Argo for a host at https://${HOST} with ASPNETCORE_ENVIRONMENT=${HOST_ENVIRONMENT}"
container('argo') {
deployK8sApplicationV2 cluster_env: 'nonprod', app_env: env.SUBDOMAIN_SUFFIX, extra_args: [
helm: [
releaseName: env.PROJECT_NAME,
values: [
image: [
"repository": "${IMAGE_REGISTRY}/${PROJECT_NAME}",
"tag": "$BUILD_TAG",
],
istio: [
hosts: [env.HOST],
],
extraEnvs: [ "ASPNETCORE_ENVIRONMENT": env.HOST_ENVIRONMENT ]
],
],
]
}
echo "Site was deployed to a host at https://${HOST}"
}
}
stage('Deploy to Prod?') {
agent none
when { anyOf { branch 'release-*'; branch 'master' } }
steps {
script {
def deployApproval = safeInput message: 'Deploy to Production?',
ok: 'Deploy to P now',
cancel: 'End job now',
timeout: 60,
timeoutUnit: 'MINUTES'
}
}
}
stage('Deploy Production') {
when { anyOf { branch 'release-*'; branch 'master' } }
environment {
HOST_ENVIRONMENT = "production"
SUBDOMAIN_SUFFIX = "prod"
HOST = "tradecars.genmills.com"
}
steps {
echo "Attempting deploy via Argo for a host at https://${HOST} with ASPNETCORE_ENVIRONMENT=${HOST_ENVIRONMENT}"
container('argo') {
deployK8sApplicationV2 cluster_env: 'prod', app_env: env.SUBDOMAIN_SUFFIX, extra_args: [
helm: [
releaseName: env.PROJECT_NAME,
values: [
image: [
"repository": "${IMAGE_REGISTRY}/${PROJECT_NAME}",
"tag": "${BUILD_NUMBER}-${GIT_COMMIT_SHORT}",
],
istio: [
hosts: [env.HOST],
],
extraEnvs: [ "ASPNETCORE_ENVIRONMENT": env.HOST_ENVIRONMENT ]
],
],
]
}
echo "Site was deployed to a host at https://${HOST}"
}
}
}
post {
always {
postBuild()
}
success {
updatePullRequestStatus state: 'succeeded'
}
failure {
updatePullRequestStatus state: 'failed'
}
}
}