mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 04:24:12 +00:00
119 lines
4.2 KiB
Groovy
119 lines
4.2 KiB
Groovy
// 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 {
|
|
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 {
|
|
HOME = '.'
|
|
}
|
|
stages {
|
|
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":
|
|
case "vapor/staging":
|
|
case "vapor/development":
|
|
println("Debug 1")
|
|
git(
|
|
url: 'https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git',
|
|
credentialsId: 'gitlab-jenkins-localhost',
|
|
branch: GIT_BRANCH
|
|
)
|
|
case "origin/dillon/34-jenkins-vapor":
|
|
println("Debug 2")
|
|
git(
|
|
url: 'https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git',
|
|
credentialsId: 'gitlab-jenkins-localhost',
|
|
branch: 'dillon/34-jenkins-vapor'
|
|
)
|
|
break
|
|
}
|
|
currentBuild.description = 'Step 2 of 6 Completed'
|
|
}
|
|
}
|
|
}
|
|
|
|
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'
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Deploy') {
|
|
steps {
|
|
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}'"
|
|
break
|
|
case "vapor/staging":
|
|
sh "vendor/bin/vapor deploy staging --message='${gitCommitMessage}'"
|
|
break
|
|
case "vapor/development":
|
|
sh "vendor/bin/vapor deploy development --message='${gitCommitMessage}'"
|
|
break
|
|
case "origin/dillon/34-jenkins-vapor":
|
|
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'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@NonCPS
|
|
String getCommitMessage(){
|
|
commitMessage = " "
|
|
for ( changeLogSet in currentBuild.changeSets){
|
|
for (entry in changeLogSet.getItems()){
|
|
commitMessage = entry.msg
|
|
}
|
|
}
|
|
return commitMessage
|
|
}
|