Jenkinsfile update to cater for Multibranch deployment through Jenkins

This commit is contained in:
Dillon Ngo
2023-11-26 22:59:18 +08:00
parent d13746665f
commit 7fd24e89f5
Vendored
+26 -14
View File
@@ -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
}
}
}
}