update: jenkinsfile code for multibranch pipeline
Employee App/pipeline/head This commit looks good Details

This commit is contained in:
adelyaou 2025-10-24 15:14:30 +07:00
parent b6150a7e32
commit 3cb374af92
1 changed files with 11 additions and 8 deletions

19
Jenkinsfile vendored
View File

@ -4,7 +4,7 @@ pipeline {
environment { environment {
REGISTRY = "docker.io/adelyao" REGISTRY = "docker.io/adelyao"
APP_NAME = "employee" APP_NAME = "employee"
MANIFEST_REPO = "https://git.winteraccess.id/adel/Employee-manifest.git" MANIFEST_REPO = "git.winteraccess.id/adel/Employee-manifest.git"
MANIFEST_CRED_ID = "GIT_CRED_ID" MANIFEST_CRED_ID = "GIT_CRED_ID"
DOCKER_CRED_ID = "DOCKER_CRED_ID" DOCKER_CRED_ID = "DOCKER_CRED_ID"
MANIFEST_DIR = "manifest" MANIFEST_DIR = "manifest"
@ -73,8 +73,8 @@ pipeline {
set -e set -e
rm -rf ${MANIFEST_DIR}-${overlayEnv} rm -rf ${MANIFEST_DIR}-${overlayEnv}
echo "Cloning manifest branch: ${overlayEnv}" echo "Cloning manifest branch: ${overlayEnv}"
git clone --single-branch --branch ${overlayEnv} https://\$GIT_USER:\$GIT_PASS@${env.MANIFEST_REPO.replace('https://', '')} ${MANIFEST_DIR}-${overlayEnv} || \ git clone --single-branch --branch ${overlayEnv} https://\$GIT_USER:\$GIT_PASS@${MANIFEST_REPO} ${MANIFEST_DIR}-${overlayEnv} || \
(git clone https://\$GIT_USER:\$GIT_PASS@${env.MANIFEST_REPO.replace('https://', '')} ${MANIFEST_DIR}-${overlayEnv} && cd ${MANIFEST_DIR}-${overlayEnv} && git checkout -b ${overlayEnv}) (git clone https://\$GIT_USER:\$GIT_PASS@${MANIFEST_REPO} ${MANIFEST_DIR}-${overlayEnv} && cd ${MANIFEST_DIR}-${overlayEnv} && git checkout -b ${overlayEnv})
""" """
dir("${MANIFEST_DIR}-${overlayEnv}") { dir("${MANIFEST_DIR}-${overlayEnv}") {
@ -83,7 +83,7 @@ pipeline {
echo "Cleaning overlays folder (keeping only ${overlayEnv})..." echo "Cleaning overlays folder (keeping only ${overlayEnv})..."
for d in overlays/*; do for d in overlays/*; do
[ -d "\$d" ] || continue [ -d "\$d" ] || continue
if [ "\$(basename \"\$d\")" != "${overlayEnv}" ]; then if [ "\$(basename "\$d")" != "${overlayEnv}" ]; then
echo "Removing \$d" echo "Removing \$d"
rm -rf "\$d" rm -rf "\$d"
fi fi
@ -96,11 +96,14 @@ pipeline {
git config user.email "jenkins@automation.local" git config user.email "jenkins@automation.local"
git config user.name "Jenkins CI" git config user.name "Jenkins CI"
git add overlays/${overlayEnv}/patch-deployment.yaml echo "Staging all changes..."
git add -A
echo "Committing changes..."
git commit -m "chore(${overlayEnv}): update image tags to ${env.IMAGE_TAG_FINAL}" || echo "No changes to commit" git commit -m "chore(${overlayEnv}): update image tags to ${env.IMAGE_TAG_FINAL}" || echo "No changes to commit"
echo "Pushing updates to branch ${overlayEnv}" echo "Pushing updates to branch ${overlayEnv}..."
git push https://\$GIT_USER:\$GIT_PASS@${env.MANIFEST_REPO.replace('https://', '')} ${overlayEnv} || echo "No push needed for ${overlayEnv}" git push https://\$GIT_USER:\$GIT_PASS@${MANIFEST_REPO} ${overlayEnv} || echo "No push needed for ${overlayEnv}"
""" """
} }
@ -129,4 +132,4 @@ pipeline {
echo "Pipeline failed. Check logs for details." echo "Pipeline failed. Check logs for details."
} }
} }
} }