Files
shipping-portal/Jenkinsfile
T

132 lines
4.7 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 = '.'
DB_CONNECTION = 'mysql'
DB_DATABASE = 'portal_development'
APP_ENV = 'testing'
}
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":
git(
url: 'https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git',
credentialsId: 'gitlab-jenkins-localhost',
branch: GIT_BRANCH
)
break
case "origin/dillon/34-jenkins-vapor":
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'
withCredentials([
usernamePassword(
credentialsId: 'shipping-portal-dev-db-credential',
usernameVariable: 'DB_USERNAME',
passwordVariable: 'DB_PASSWORD'
),
string(credentialsId: 'shipping-portal-dev-db-host', variable: 'DB_HOST')
]) {
// sh 'vendor/bin/phpunit --filter ListOrderTrackingLogicTest'
}
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
}
}
commitMessage = commitMessage.replace("'", "`")
return commitMessage
}