-
Notifications
You must be signed in to change notification settings - Fork 3
/
Jenkinsfile
92 lines (82 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
#!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: 'INFRASTRUCTURE', value: 'secure'],
[$class: 'StringParameterValue', name: 'INVENTORY', value: environment],
[$class: 'StringParameterValue', name: 'PLAYBOOK', value: 'deploy.yml'],
[$class: 'StringParameterValue', name: 'PLAYBOOKPARAMS', value: "-e cmdb_id=app_looplijsten-frontend"]
]
}
pipeline {
agent any
environment {
DOCKER_IMAGE = "fixxx/looplijsten-frontend"
DOCKER_IMAGE_URL = "${DOCKER_REGISTRY_NO_PROTOCOL}/${DOCKER_IMAGE}"
}
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.
// (looplijsten 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} " +
" .")
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"
}
}
}
}