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')]) {
|
||||
sh """
|
||||
echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin
|
||||
echo "\$DOCKER_PASS" | docker login -u "\$DOCKER_USER" --password-stdin
|
||||
|
||||
# Build & push backend
|
||||
docker build -t ${REGISTRY}/${APP_NAME}-be:${tag} ./employee-be
|
||||
|
|
@ -68,27 +68,29 @@ pipeline {
|
|||
steps {
|
||||
script {
|
||||
withCredentials([usernamePassword(credentialsId: env.MANIFEST_CRED_ID, usernameVariable: 'GIT_USER', passwordVariable: 'GIT_PASS')]) {
|
||||
|
||||
// Clone manifest repo pakai credential
|
||||
sh """
|
||||
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) {
|
||||
env.BRANCHES.split().each { envName ->
|
||||
echo "🔹 Updating manifests for environment: ${envName}"
|
||||
dir(env.MANIFEST_DIR) {
|
||||
env.BRANCHES.split().each { envName ->
|
||||
echo "🔹 Updating manifests for environment: ${envName}"
|
||||
|
||||
sh """
|
||||
git checkout ${envName} || git checkout -b ${envName}
|
||||
sh """
|
||||
git checkout ${envName} || git checkout -b ${envName}
|
||||
|
||||
# Update backend & frontend image tags di overlay sesuai environment
|
||||
yq e -i '.spec.template.spec.containers[0].image = "${REGISTRY}/${APP_NAME}-be:${envName}-${env.IMAGE_TAG_FINAL}"' overlays/${envName}/backend/patch-deployment.yaml
|
||||
yq e -i '.spec.template.spec.containers[0].image = "${REGISTRY}/${APP_NAME}-fe:${envName}-${env.IMAGE_TAG_FINAL}"' overlays/${envName}/frontend/patch-deployment.yaml
|
||||
# Update backend & frontend image tags di overlay sesuai environment
|
||||
yq e -i '.spec.template.spec.containers[0].image = "${REGISTRY}/${APP_NAME}-be:${envName}-${env.IMAGE_TAG_FINAL}"' overlays/${envName}/backend/patch-deployment.yaml
|
||||
yq e -i '.spec.template.spec.containers[0].image = "${REGISTRY}/${APP_NAME}-fe:${envName}-${env.IMAGE_TAG_FINAL}"' 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 push https://${GIT_USER}:${GIT_PASS}@${env.MANIFEST_REPO.replace('https://', '')} ${envName}
|
||||
"""
|
||||
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 push https://\$GIT_USER:\$GIT_PASS@${env.MANIFEST_REPO.replace('https://', '')} ${envName}
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -104,10 +106,10 @@ pipeline {
|
|||
|
||||
post {
|
||||
success {
|
||||
echo "GitOps pipeline completed successfully for dev, stag, and prod!"
|
||||
echo "✅ GitOps pipeline completed successfully for dev, stag, and prod!"
|
||||
}
|
||||
failure {
|
||||
echo "Pipeline failed. Check logs for details."
|
||||
echo "❌ Pipeline failed. Check logs for details."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue