update: jenkinsfile code for multibranch pipeline

This commit is contained in:
adelyaou 2025-10-24 13:36:47 +07:00
parent 151c8970c4
commit a2a9ac5ac2
1 changed files with 9 additions and 9 deletions

18
Jenkinsfile vendored
View File

@ -55,24 +55,24 @@ pipeline {
echo "Cleaning overlays folder, keeping only ${overlayEnv}..."
for d in overlays/*; do
[ -d "\\\$d" ] || continue
if [ "\\\$(basename "\\\$d")" != "${overlayEnv}" ]; then
echo "Removing \\\$d"
rm -rf "\\\$d"
[ -d "\$d" ] || continue
if [ "\$(basename \"\$d\")" != "${overlayEnv}" ]; then
echo "Removing \$d"
rm -rf "\$d"
fi
done
echo "Updating image tags for ${overlayEnv}..."
yq e -i '(.spec.template.spec.containers[] | select(.name == "backend") | .image) = "${REGISTRY}/${APP_NAME}-be:${IMAGE_TAG_FINAL}"' overlays/${overlayEnv}/patch-deployment.yaml
yq e -i '(.spec.template.spec.containers[] | select(.name == "frontend") | .image) = "${REGISTRY}/${APP_NAME}-fe:${IMAGE_TAG_FINAL}"' overlays/${overlayEnv}/patch-deployment.yaml
yq e -i '(.spec.template.spec.containers[] | select(.name == "backend") | .image) = "${REGISTRY}/${APP_NAME}-be:${overlayEnv}-${env.IMAGE_TAG_FINAL}"' overlays/${overlayEnv}/patch-deployment.yaml
yq e -i '(.spec.template.spec.containers[] | select(.name == "frontend") | .image) = "${REGISTRY}/${APP_NAME}-fe:${overlayEnv}-${env.IMAGE_TAG_FINAL}"' overlays/${overlayEnv}/patch-deployment.yaml
git config user.email "jenkins@automation.local"
git config user.name "Jenkins CI"
git add overlays/${overlayEnv}/patch-deployment.yaml
git commit -m "chore(${overlayEnv}): update image tags to ${IMAGE_TAG_FINAL}" || echo "No changes to commit"
git commit -m "chore(${overlayEnv}): update image tags to ${overlayEnv}-${env.IMAGE_TAG_FINAL}" || echo "No changes to commit"
echo "Pushing updates to branch ${overlayEnv}"
git push https://\${GIT_USER}:\${GIT_PASS}@${MANIFEST_REPO.replace('https://', '')} ${overlayEnv} || echo "No push needed for ${overlayEnv}"
git push https://\$GIT_USER:\$GIT_PASS@${env.MANIFEST_REPO.replace('https://', '')} ${overlayEnv} || echo "No push needed for ${overlayEnv}"
"""
}
}
@ -87,4 +87,4 @@ pipeline {
echo 'Pipeline failed. Please check logs.'
}
}
}
}