update Jenkinsfile for Pipeline gitops workflow

This commit is contained in:
Syifa 2025-10-22 11:17:24 +07:00
parent 990abb35cb
commit 5bf7611291
1 changed files with 9 additions and 9 deletions

18
Jenkinsfile vendored
View File

@ -13,7 +13,7 @@ pipeline {
stages {
stage('Checkout Source Code') {
steps {
echo "📦 Cloning main application repository..."
echo "Cloning main application repository..."
checkout scm
}
}
@ -21,7 +21,7 @@ pipeline {
stage('Build & Push Backend') {
steps {
script {
echo "⚙️ Building backend image..."
echo "Building backend image..."
withCredentials([usernamePassword(credentialsId: 'gitops-dockerhub', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
sh '''
docker login -u $DOCKER_USER -p $DOCKER_PASS
@ -40,7 +40,7 @@ pipeline {
stage('Build & Push Frontend') {
steps {
script {
echo "⚙️ Building frontend image..."
echo "Building frontend image..."
withCredentials([usernamePassword(credentialsId: 'gitops-dockerhub', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
sh '''
docker login -u $DOCKER_USER -p $DOCKER_PASS
@ -59,12 +59,12 @@ pipeline {
stage('Update GitOps Repo') {
steps {
script {
echo "📝 Updating deployment manifests in GitOps repo..."
echo "Updating deployment manifests in GitOps repo..."
withCredentials([usernamePassword(credentialsId: 'gitea-token-gitops', usernameVariable: 'GITEA_USER', passwordVariable: 'GITEA_PASS')]) {
sh '''
# Install yq kalau belum terpasang
if ! command -v yq &> /dev/null; then
echo "📥 Installing yq..."
echo "Installing yq..."
wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
chmod +x /usr/local/bin/yq
fi
@ -75,7 +75,7 @@ pipeline {
cd gitops
# Update image tag dengan yq
echo "🔧 Updating image tags..."
echo "Updating image tags..."
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 == \\"frontend\\").image = env(FRONTEND_TAG)" ${DEPLOY_OVERLAY}/patch-deployment.yaml
@ -94,14 +94,14 @@ pipeline {
post {
success {
echo "GitOps update successful — manifests updated in ${DEPLOY_OVERLAY}"
echo "GitOps update successful — manifests updated in ${DEPLOY_OVERLAY}"
}
failure {
echo "Pipeline failed, check Jenkins logs for details."
echo "Pipeline failed, check Jenkins logs for details."
}
always {
cleanWs()
echo "🧹 Workspace cleaned up."
echo "Workspace cleaned up."
}
}
}