This repository has been archived by the owner on Feb 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
82 lines (69 loc) · 2.05 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
#!groovy
def tag_image_as(imageUrl, tag) {
script {
docker.image("${imageUrl}:${env.BUILD_NUMBER}").push(tag)
sh "docker rmi ${imageUrl}:${tag} || true"
}
}
def deploy(app, 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_${app}"],
]
}
pipeline {
agent any
environment {
GROUP = "vnor"
BACKEND_APP = "bereikbaarheid-backend"
BACKEND_DOCKERFILE = "Dockerfile"
BACKEND_DOCKER_BUILD_CONTEXT = "."
BACKEND_DOCKER_IMAGE = "${GROUP}/${BACKEND_APP}"
BACKEND_DOCKER_IMAGE_URL = "${DOCKER_REGISTRY_NO_PROTOCOL}/${BACKEND_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") {
steps {
script {
def backend_image = docker.build("${BACKEND_DOCKER_IMAGE_URL}:${env.BUILD_NUMBER}","-f ${BACKEND_DOCKERFILE} ${BACKEND_DOCKER_BUILD_CONTEXT}")
backend_image.push()
}
}
}
stage("Push and deploy acceptance image") {
when { branch 'main' }
steps {
tag_image_as("${BACKEND_DOCKER_IMAGE_URL}", "acceptance")
deploy("${BACKEND_APP}", "acceptance")
}
}
stage("Deploy to production") {
when { branch 'main' }
options {
timeout(time: 6, unit: 'HOURS')
}
input {
message "Deploy to Production?"
ok "Yes, deploy it!"
}
steps {
tag_image_as("${BACKEND_DOCKER_IMAGE_URL}", "latest")
tag_image_as("${BACKEND_DOCKER_IMAGE_URL}", "production")
deploy("${BACKEND_APP}", "production")
}
}
}
post {
always {
script { sh "docker rmi ${BACKEND_DOCKER_IMAGE_URL}:${env.BUILD_NUMBER} || true" }
}
}
}