update Jenkinsfile for workflow gitops
This commit is contained in:
parent
642ab59f5e
commit
663ddd17d0
|
|
@ -65,38 +65,42 @@ pipeline {
|
||||||
|
|
||||||
withCredentials([usernamePassword(credentialsId: 'gitea-token-gitops', usernameVariable: 'GITEA_USER', passwordVariable: 'GITEA_PASS')]) {
|
withCredentials([usernamePassword(credentialsId: 'gitea-token-gitops', usernameVariable: 'GITEA_USER', passwordVariable: 'GITEA_PASS')]) {
|
||||||
branches.each { envSet ->
|
branches.each { envSet ->
|
||||||
sh """
|
|
||||||
echo "=============================="
|
echo "=============================="
|
||||||
echo "Updating GitOps for branch: ${envSet.name}"
|
echo "Updating GitOps for branch: ${envSet.name}"
|
||||||
echo "=============================="
|
echo "=============================="
|
||||||
|
|
||||||
# Install yq kalau belum ada
|
// Gunakan block dengan masking aktif
|
||||||
if ! command -v ./yq &> /dev/null; then
|
sh(
|
||||||
echo "Installing yq locally..."
|
script: """
|
||||||
wget -qO ./yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
|
# Install yq kalau belum ada
|
||||||
chmod +x ./yq
|
if ! command -v ./yq &> /dev/null; then
|
||||||
fi
|
echo "Installing yq locally..."
|
||||||
|
wget -qO ./yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
|
||||||
|
chmod +x ./yq
|
||||||
|
fi
|
||||||
|
|
||||||
# Clone branch GitOps yang sesuai
|
# Clone branch GitOps yang sesuai
|
||||||
rm -rf gitops
|
rm -rf gitops
|
||||||
git -c http.sslVerify=false clone -b ${envSet.name} https://$GITEA_USER:$GITEA_PASS@git.winteraccess.id/syifa/datasiswa-gitops.git gitops
|
git -c http.sslVerify=false clone -b ${envSet.name} https://$GITEA_USER:$GITEA_PASS@git.winteraccess.id/syifa/datasiswa-gitops.git gitops
|
||||||
cd gitops
|
cd gitops
|
||||||
|
|
||||||
# Update image tags
|
# Update image tags
|
||||||
echo "Updating ${envSet.overlay}/patch-deployment.yaml..."
|
echo "Updating ${envSet.overlay}/patch-deployment.yaml..."
|
||||||
../yq e -i ".spec.template.spec.containers[] |= select(.name == \\"backend\\").image = env(BACKEND_TAG)" ${envSet.overlay}/patch-deployment.yaml
|
../yq e -i ".spec.template.spec.containers[] |= select(.name == \\"backend\\").image = env(BACKEND_TAG)" ${envSet.overlay}/patch-deployment.yaml
|
||||||
../yq e -i ".spec.template.spec.containers[] |= select(.name == \\"frontend\\").image = env(FRONTEND_TAG)" ${envSet.overlay}/patch-deployment.yaml
|
../yq e -i ".spec.template.spec.containers[] |= select(.name == \\"frontend\\").image = env(FRONTEND_TAG)" ${envSet.overlay}/patch-deployment.yaml
|
||||||
|
|
||||||
# Commit & push
|
# Commit & push
|
||||||
git config user.name "jenkins"
|
git config user.name "jenkins"
|
||||||
git config user.email "jenkins@gitea.local"
|
git config user.email "jenkins@gitea.local"
|
||||||
git add .
|
git add .
|
||||||
git commit -m "Update ${envSet.overlay}: backend=${BUILD_NUMBER}, frontend=${BUILD_NUMBER}" || echo "No changes to commit"
|
git commit -m "Update ${envSet.overlay}: backend=${BUILD_NUMBER}, frontend=${BUILD_NUMBER}" || echo "No changes to commit"
|
||||||
git push origin ${envSet.name}
|
git push origin ${envSet.name}
|
||||||
|
|
||||||
cd ..
|
cd ..
|
||||||
rm -rf gitops
|
rm -rf gitops
|
||||||
"""
|
""",
|
||||||
|
mask: true // <--- ini kunci masking password dari log
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -106,14 +110,14 @@ pipeline {
|
||||||
|
|
||||||
post {
|
post {
|
||||||
success {
|
success {
|
||||||
echo "✅ GitOps update successful — all branches (dev, staging, prod) updated!"
|
echo "GitOps update successful — all branches (dev, staging, prod) updated!"
|
||||||
}
|
}
|
||||||
failure {
|
failure {
|
||||||
echo "❌ Pipeline failed, check Jenkins logs for details."
|
echo "Pipeline failed, check Jenkins logs for details."
|
||||||
}
|
}
|
||||||
always {
|
always {
|
||||||
cleanWs()
|
cleanWs()
|
||||||
echo "🧹 Workspace cleaned up."
|
echo "Workspace cleaned up."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue