-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
93 lines (83 loc) · 2.43 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
// tag image, push to repo, remove local tagged image
def tag_image_as(tag) {
script {
docker.image("${DOCKER_IMAGE_URL}:${env.COMMIT_HASH}").push(tag)
sh "docker rmi ${DOCKER_IMAGE_URL}:${tag} || true"
}
}
def deploy(environment) {
build job: 'Subtask_Openstack_Playbook',
parameters: [
[$class: 'StringParameterValue', name: 'INVENTORY', value: environment],
[$class: 'StringParameterValue', name: 'PLAYBOOK', value: 'deploy.yml'],
[$class: 'StringParameterValue', name: 'PLAYBOOKPARAMS', value: "-e cmdb_id=app_${env.APP}"],
]
}
pipeline {
agent any
environment {
DOCKER_IMAGE = "fixxx/zaken-frontend"
APP = "zaken-frontend"
DOCKER_IMAGE_URL = "${DOCKER_REGISTRY_NO_PROTOCOL}/fixxx/zaken-frontend"
}
stages {
stage("Checkout") {
steps {
checkout scm
script {
env.COMMIT_HASH = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim()
}
}
}
stage("Build docker image") {
// We only build a docker image when we're not deploying to production,
// to make make sure images deployed to production are deployed to
// acceptance first.
//
// To deploy to production, tag an existing commit (that has already been
// build) and push the tag.
// (zaken-frontend actually wants to be able to hotfix to production,
// without passing through acceptance)
//when { not { buildingTag() } }
steps {
script {
def image = docker.build("${DOCKER_IMAGE_URL}:${env.COMMIT_HASH}",
"--no-cache " +
"--shm-size 1G " +
"--build-arg COMMIT_HASH=${env.COMMIT_HASH} " +
"--build-arg BRANCH_NAME=${env.BRANCH_NAME} " +
" .")
image.push()
tag_image_as("latest")
}
}
}
stage("Push and deploy acceptance image") {
when {
not { buildingTag() }
branch 'main'
}
steps {
tag_image_as("acceptance")
deploy("acceptance")
}
}
stage("Push and deploy production image") {
when { buildingTag() }
steps {
tag_image_as("production")
tag_image_as(env.TAG_NAME)
deploy("production")
}
}
}
post {
always {
script {
// delete original image built on the build server
sh "docker rmi ${DOCKER_IMAGE_URL}:${env.COMMIT_HASH} || true"
}
}
}
}