From 7fd24e89f562c5c39b163d36ce8bc058e57d25d3 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Sun, 26 Nov 2023 22:59:18 +0800 Subject: [PATCH] Jenkinsfile update to cater for Multibranch deployment through Jenkins --- Jenkinsfile | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c838459..0767031 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,11 +1,3 @@ -// Webhook + Gitlab git pull + Vapor - -def payload = readJSON text: "${payload}" -String userName = payload.user_name -String userEmail = payload.user_email -String httpUrl = payload.project.http_url - - pipeline { agent { docker { @@ -19,11 +11,24 @@ pipeline { stages { stage('Download source code from Git') { steps { - git( - url: httpUrl, - credentialsId: 'gitlab-jenkins-localhost', - branch: 'test' - ) + script{ + switch(GIT_BRANCH) { + case "vapor/production": + git( + url: 'https://gitlab.com/CIEFWorldwideSdnBhd/vapor-laravel-explore.git', + credentialsId: 'gitlab-jenkins-localhost', + branch: 'vapor/production' + ) + break + case "vapor/staging": + git( + url: 'https://gitlab.com/CIEFWorldwideSdnBhd/vapor-laravel-explore.git', + credentialsId: 'gitlab-jenkins-localhost', + branch: 'vapor/staging' + ) + break + } + } } } @@ -44,7 +49,14 @@ pipeline { script{ String gitCommitMessage = getCommitMessage() println("GIT CommitMessage: " + gitCommitMessage) - sh "vendor/bin/vapor deploy staging --message='${gitCommitMessage}'" + switch(GIT_BRANCH) { + case "vapor/production": + sh "vendor/bin/vapor deploy production --message='${gitCommitMessage}'" + break + case "vapor/staging": + sh "vendor/bin/vapor deploy staging --message='${gitCommitMessage}'" + break + } } } }