Update Jenkinsfile

This commit is contained in:
Dillon Ngo
2024-09-08 01:44:10 +08:00
parent 1226b4248a
commit b03f9d48c8
Vendored
+29 -15
View File
@@ -1,8 +1,10 @@
pipeline {
agent {
docker {
image 'dillonngo/docker-based-image:poc'
args "--group-add 992 -v /var/run/docker.sock:/var/run/docker.sock"
args '--group-add 992 -v /var/run/docker.sock:/var/run/docker.sock'
image '303644228504.dkr.ecr.ap-southeast-1.amazonaws.com/jenkins-pipeline-agent:latest'
registryCredentialsId "ecr:ap-southeast-1:aws-ec2-instance-iam-role"
registryUrl "https://303644228504.dkr.ecr.ap-southeast-1.amazonaws.com"
}
}
environment {
@@ -12,26 +14,16 @@ pipeline {
stage('Download source code from Git') {
steps {
script{
currentBuild.description = 'Step 1 of 6 Completed'
println("GIT GIT_BRANCH: " + GIT_BRANCH)
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
case "vapor/development":
git(
url: 'https://gitlab.com/CIEFWorldwideSdnBhd/vapor-laravel-explore.git',
credentialsId: 'gitlab-jenkins-localhost',
branch: 'vapor/development'
branch: GIT_BRANCH
)
break
case "origin/test":
@@ -42,6 +34,7 @@ pipeline {
)
break
}
currentBuild.description = 'Step 2 of 6 Completed'
}
}
}
@@ -49,12 +42,18 @@ pipeline {
stage('Install') {
steps {
sh 'composer update'
script{
currentBuild.description = 'Step 3 of 6 Completed'
}
}
}
stage('Tests') {
steps {
sh 'vendor/bin/phpunit tests/Unit'
script{
currentBuild.description = 'Step 4 of 6 Completed'
}
}
}
@@ -63,6 +62,7 @@ pipeline {
script{
String gitCommitMessage = getCommitMessage()
println("GIT CommitMessage: " + gitCommitMessage)
println("GIT GIT_BRANCH: " + GIT_BRANCH)
switch(GIT_BRANCH) {
case "vapor/production":
sh "vendor/bin/vapor deploy production --message='${gitCommitMessage}'"
@@ -77,10 +77,23 @@ pipeline {
sh "vendor/bin/vapor deploy development --message='${gitCommitMessage}'"
break
}
currentBuild.description = 'Step 5 of 6 Completed'
}
}
}
stage('Cleanup') {
steps {
script {
try {
sh 'docker image prune -a -f'
} catch (Exception e) {
echo "Error during cleanup: ${e.message}"
}
currentBuild.description = 'Step 6 of 6 Completed'
}
}
}
}
}
@@ -92,5 +105,6 @@ String getCommitMessage(){
commitMessage = entry.msg
}
}
commitMessage = commitMessage.replace("'", "`")
return commitMessage
}