Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Revert "Update Jenkinsfile"" #253

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 93 additions & 75 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,91 +1,109 @@
#!groovy

def tryStep(String message, Closure block, Closure tearDown = null) {
try {
block()
}
catch (Throwable t) {
slackSend message: "${env.JOB_NAME}: ${message} failure ${env.BUILD_URL}", channel: '#ci-channel', color: 'danger'

throw t
}
finally {
if (tearDown) {
tearDown()
}
}
}

String BUILD_ID = "${Math.abs(new Random().nextInt() % 600) + 1}"

node {
stage("Checkout") {
checkout scm
def PROJECT_NAME = "hior"
def SLACK_CHANNEL = '#opdrachten-deployments'
def PLAYBOOK = 'deploy.yml'
def CMDB_ID = 'app_hior'
def SLACK_MESSAGE = [
"title_link": BUILD_URL,
"fields": [
["title": "Project","value": PROJECT_NAME],
["title":"Branch", "value": BRANCH_NAME, "short":true],
["title":"Build number", "value": BUILD_NUMBER, "short":true]
]
]


pipeline {
agent any

options {
timeout(time: 1, unit: 'HOURS')
}
}

node {
stage("Build and push acceptance image") {

tryStep "build image", {
def image = docker.build("docker-registry.secure.amsterdam.nl/ruimte/hior:${BUILD_ID}",
"--shm-size 1G " +
"--build-arg BUILD_NUMBER=${BUILD_ID} " +
". ")

image.push("acceptance")
}
environment {
SHORT_UUID = sh( script: "uuidgen | cut -d '-' -f1", returnStdout: true).trim()
COMPOSE_PROJECT_NAME = "${PROJECT_NAME}-${env.SHORT_UUID}"
VERSION = env.BRANCH_NAME.replace('/', '-').toLowerCase().replace(
'main', 'latest'
)
}
}


String BRANCH = "${env.BRANCH_NAME}"


if (BRANCH == "main") {
node {
stage("Deploy to ACC") {
tryStep "deployment", {
build job: 'Subtask_Openstack_Playbook',
parameters: [
[$class: 'StringParameterValue', name: 'INVENTORY', value: 'acceptance'],
[$class: 'StringParameterValue', name: 'PLAYBOOK', value: 'deploy.yml'],
[$class: 'StringParameterValue', name: 'PLAYBOOKPARAMS', value: "-e cmdb_id=app_hior"]
]
stages {
stage('Test') {
steps {
sh 'make test'
}
}
}
}

if (BRANCH == "main") {

stage('Waiting for approval') {
slackSend channel: '#ci-channel', color: 'warning', message: 'HIOR Dashboard is waiting for Production Release - please confirm'
timeout(10) {
input "Deploy to Production?"
stage('Build') {
steps {
sh 'make build'
}
}
}

node {
stage("Push Production image") {
tryStep "build", {
def image = docker.image("docker-registry.secure.amsterdam.nl/ruimte/hior:${BUILD_ID}")
image.push("production")
image.push("latest")
stage('Push and deploy') {
when {
anyOf {
branch 'main'
buildingTag()
}
}
stages {
stage('Push') {
steps {
retry(3) {
sh 'make push'
}
}
}

stage('Deploy to acceptance') {
when {
branch 'main'
}
steps {
sh 'VERSION=acceptance make push'
build job: 'Subtask_Openstack_Playbook', parameters: [
string(name: 'PLAYBOOK', value: PLAYBOOK),
string(name: 'INVENTORY', value: "acceptance"),
string(
name: 'PLAYBOOKPARAMS',
value: "-e 'deployversion=${VERSION} cmdb_id=${CMDB_ID}'"
)
], wait: true
}
}

stage('Deploy to production') {
when { buildingTag() }
steps {
sh 'VERSION=production make push'
build job: 'Subtask_Openstack_Playbook', parameters: [
string(name: 'PLAYBOOK', value: PLAYBOOK),
string(name: 'INVENTORY', value: "production"),
string(
name: 'PLAYBOOKPARAMS',
value: "-e 'deployversion=${VERSION} cmdb_id=${CMDB_ID}'"
)
], wait: true
}
}
}
}
}


node {
stage("Deploy") {
tryStep "deployment", {
build job: 'Subtask_Openstack_Playbook',
parameters: [
[$class: 'StringParameterValue', name: 'INVENTORY', value: 'production'],
[$class: 'StringParameterValue', name: 'PLAYBOOK', value: 'deploy.yml'],
[$class: 'StringParameterValue', name: 'PLAYBOOKPARAMS', value: "-e cmdb_id=app_hior"] ]
}
}
post {
always {
sh 'make clean'
}
failure {
slackSend(channel: SLACK_CHANNEL, attachments: [SLACK_MESSAGE <<
[
"color": "#D53030",
"title": "Build failed :fire:",
]
])
}
}
}