update: jenkinsfile code for multibranch pipeline
This commit is contained in:
parent
00fce47934
commit
fec8b625e4
|
|
@ -45,7 +45,7 @@ pipeline {
|
||||||
|
|
||||||
withCredentials([usernamePassword(credentialsId: env.DOCKER_CRED_ID, usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
|
withCredentials([usernamePassword(credentialsId: env.DOCKER_CRED_ID, usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
|
||||||
sh """
|
sh """
|
||||||
echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin
|
echo "\$DOCKER_PASS" | docker login -u "\$DOCKER_USER" --password-stdin
|
||||||
|
|
||||||
# Build & push backend
|
# Build & push backend
|
||||||
docker build -t ${REGISTRY}/${APP_NAME}-be:${tag} ./employee-be
|
docker build -t ${REGISTRY}/${APP_NAME}-be:${tag} ./employee-be
|
||||||
|
|
@ -68,11 +68,12 @@ pipeline {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
withCredentials([usernamePassword(credentialsId: env.MANIFEST_CRED_ID, usernameVariable: 'GIT_USER', passwordVariable: 'GIT_PASS')]) {
|
withCredentials([usernamePassword(credentialsId: env.MANIFEST_CRED_ID, usernameVariable: 'GIT_USER', passwordVariable: 'GIT_PASS')]) {
|
||||||
|
|
||||||
|
// Clone manifest repo pakai credential
|
||||||
sh """
|
sh """
|
||||||
rm -rf ${MANIFEST_DIR}
|
rm -rf ${MANIFEST_DIR}
|
||||||
git clone https://${GIT_USER}:${GIT_PASS}@${env.MANIFEST_REPO.replace('https://', '')} ${MANIFEST_DIR}
|
git clone https://\$GIT_USER:\$GIT_PASS@${env.MANIFEST_REPO.replace('https://', '')} ${MANIFEST_DIR}
|
||||||
"""
|
"""
|
||||||
}
|
|
||||||
|
|
||||||
dir(env.MANIFEST_DIR) {
|
dir(env.MANIFEST_DIR) {
|
||||||
env.BRANCHES.split().each { envName ->
|
env.BRANCHES.split().each { envName ->
|
||||||
|
|
@ -87,13 +88,14 @@ pipeline {
|
||||||
|
|
||||||
git add overlays/${envName}/backend/patch-deployment.yaml overlays/${envName}/frontend/patch-deployment.yaml
|
git add overlays/${envName}/backend/patch-deployment.yaml overlays/${envName}/frontend/patch-deployment.yaml
|
||||||
git commit -m "chore(${envName}): update image tags to ${envName}-${env.IMAGE_TAG_FINAL}" || echo "No changes for ${envName}"
|
git commit -m "chore(${envName}): update image tags to ${envName}-${env.IMAGE_TAG_FINAL}" || echo "No changes for ${envName}"
|
||||||
git push https://${GIT_USER}:${GIT_PASS}@${env.MANIFEST_REPO.replace('https://', '')} ${envName}
|
git push https://\$GIT_USER:\$GIT_PASS@${env.MANIFEST_REPO.replace('https://', '')} ${envName}
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stage('ArgoCD Sync (optional)') {
|
stage('ArgoCD Sync (optional)') {
|
||||||
steps {
|
steps {
|
||||||
|
|
@ -104,10 +106,10 @@ pipeline {
|
||||||
|
|
||||||
post {
|
post {
|
||||||
success {
|
success {
|
||||||
echo "GitOps pipeline completed successfully for dev, stag, and prod!"
|
echo "✅ GitOps pipeline completed successfully for dev, stag, and prod!"
|
||||||
}
|
}
|
||||||
failure {
|
failure {
|
||||||
echo "Pipeline failed. Check logs for details."
|
echo "❌ Pipeline failed. Check logs for details."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue