-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
93 lines (86 loc) · 3.56 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
#!groovy
// Project Settings for Deployment
String PROJECTNAME = "processen-verbaal"
String CONTAINERDIR = "."
String PRODUCTION_BRANCH = "master"
String ACCEPTANCE_BRANCH = "development"
String PRODUCTION_ROOT_URL = "https://static.amsterdam.nl/processen-verbaal"
String ACCEPTANCE_ROOT_URL = "https://acc.static.amsterdam.nl/processen-verbaal"
String INFRASTRUCTURE = 'thanos'
String PLAYBOOK = 'deploy.yml'
// All other data uses variables, no changes needed for static
String CONTAINERNAME = "docker-registry.data.amsterdam.nl/static/${PROJECTNAME}:${env.BUILD_NUMBER}"
String BRANCH = "${env.BRANCH_NAME}"
image = 'initial value'
def tryStep(String message, Closure block, Closure tearDown = null) {
try {
block();
}
catch (Throwable t) {
// Disable while developing
// slackSend message: "${env.JOB_NAME}: ${message} failure ${env.BUILD_URL}", channel: '#ci-channel', color: 'danger'
throw t;
}
finally {
if (tearDown) {
tearDown();
}
}
}
node {
// Get a copy of the code
stage("Checkout") {
checkout scm
}
}
// Acceptance branch
if (BRANCH == "${ACCEPTANCE_BRANCH}") {
node {
// Build the Dockerfile in the $CONTAINERDIR, pass REACT_APP_URL environment variable and push it to Nexus
stage("Build develop image") {
tryStep "build", {
image = docker.build("${CONTAINERNAME}", "--build-arg REACT_APP_URL=${ACCEPTANCE_ROOT_URL} ${CONTAINERDIR}")
image.push()
}
}
// fetch the container, label with acceptance and deploy to acceptance.
stage("Deploy to ACC") {
tryStep "deployment", {
image.push("acceptance")
build job: 'Subtask_Openstack_Playbook',
parameters: [
[$class: 'StringParameterValue', name: 'INFRASTRUCTURE', value: "${INFRASTRUCTURE}"],
[$class: 'StringParameterValue', name: 'INVENTORY', value: 'acceptance'],
[$class: 'StringParameterValue', name: 'PLAYBOOK', value: "${PLAYBOOK}"],
[$class: 'StringParameterValue', name: 'PLAYBOOKPARAMS', value: "-e cmdb_id=app_${PROJECTNAME}"],
]
}
}
}
}
// Master branch
if (BRANCH == "${PRODUCTION_BRANCH}") {
node {
// Build the Dockerfile in the $CONTAINERDIR, pass REACT_APP_URL environment variable and push it to Nexus
stage("Build develop image") {
tryStep "build", {
image = docker.build("${CONTAINERNAME}", "--build-arg REACT_APP_URL=${PRODUCTION_ROOT_URL} ${CONTAINERDIR}")
image.push()
}
}
// fetch the container, tag with production and latest and deploy to production
stage("Deploy to PROD") {
tryStep "deployment", {
image.push("production")
image.push("latest")
build job: 'Subtask_Openstack_Playbook',
parameters: [
[$class: 'StringParameterValue', name: 'INFRASTRUCTURE', value: "${INFRASTRUCTURE}"],
[$class: 'StringParameterValue', name: 'INVENTORY', value: 'production'],
[$class: 'StringParameterValue', name: 'PLAYBOOK', value: "${PLAYBOOK}"],
[$class: 'StringParameterValue', name: 'PLAYBOOKPARAMS', value: "-e cmdb_id=app_${PROJECTNAME}"],
]
}
}
}
}