update Jenkinsfile for gitops workflow
This commit is contained in:
parent
6643739c61
commit
d2b6391742
|
|
@ -6,8 +6,6 @@ pipeline {
|
||||||
BACKEND_NAME = "backend-app"
|
BACKEND_NAME = "backend-app"
|
||||||
FRONTEND_NAME = "frontend-app"
|
FRONTEND_NAME = "frontend-app"
|
||||||
GITOPS_REPO = "https://git.winteraccess.id/syifa/datasiswa-gitops.git"
|
GITOPS_REPO = "https://git.winteraccess.id/syifa/datasiswa-gitops.git"
|
||||||
GITOPS_BRANCH = "dev"
|
|
||||||
DEPLOY_OVERLAY = "overlays/dev"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
|
|
@ -56,36 +54,50 @@ pipeline {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Update GitOps Repo') {
|
stage('Update GitOps Repos (dev, staging, production)') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
echo "Updating deployment manifests in GitOps repo..."
|
def branches = [
|
||||||
|
[name: "dev", overlay: "overlays/dev"],
|
||||||
|
[name: "staging", overlay: "overlays/staging"],
|
||||||
|
[name: "production", overlay: "overlays/production"]
|
||||||
|
]
|
||||||
|
|
||||||
withCredentials([usernamePassword(credentialsId: 'gitea-token-gitops', usernameVariable: 'GITEA_USER', passwordVariable: 'GITEA_PASS')]) {
|
withCredentials([usernamePassword(credentialsId: 'gitea-token-gitops', usernameVariable: 'GITEA_USER', passwordVariable: 'GITEA_PASS')]) {
|
||||||
sh '''
|
branches.each { envSet ->
|
||||||
# Install yq lokal (tanpa root)
|
sh """
|
||||||
|
echo "=============================="
|
||||||
|
echo "Updating GitOps for branch: ${envSet.name}"
|
||||||
|
echo "=============================="
|
||||||
|
|
||||||
|
# Install yq kalau belum ada
|
||||||
if ! command -v ./yq &> /dev/null; then
|
if ! command -v ./yq &> /dev/null; then
|
||||||
echo "Installing yq locally..."
|
echo "Installing yq locally..."
|
||||||
wget -qO ./yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
|
wget -qO ./yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
|
||||||
chmod +x ./yq
|
chmod +x ./yq
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Clone repo GitOps
|
# Clone branch GitOps yang sesuai
|
||||||
rm -rf gitops
|
rm -rf gitops
|
||||||
git -c http.sslVerify=false clone -b $GITOPS_BRANCH 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 tag pakai yq lokal
|
# Update image tags
|
||||||
echo "Updating image tags..."
|
echo "Updating ${envSet.overlay}/patch-deployment.yaml..."
|
||||||
../yq e -i ".spec.template.spec.containers[] |= select(.name == \\"backend\\").image = env(BACKEND_TAG)" ${DEPLOY_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)" ${DEPLOY_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 perubahan
|
# 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 ${DEPLOY_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 $GITOPS_BRANCH
|
git push origin ${envSet.name}
|
||||||
'''
|
|
||||||
|
cd ..
|
||||||
|
rm -rf gitops
|
||||||
|
"""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -94,14 +106,14 @@ pipeline {
|
||||||
|
|
||||||
post {
|
post {
|
||||||
success {
|
success {
|
||||||
echo "GitOps update successful — manifests updated in ${DEPLOY_OVERLAY}"
|
echo "✅ GitOps update successful — all branches (dev, staging, production) 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