update Jenkinsfile for Pipeline gitops workflow
This commit is contained in:
parent
990abb35cb
commit
5bf7611291
|
|
@ -13,7 +13,7 @@ pipeline {
|
||||||
stages {
|
stages {
|
||||||
stage('Checkout Source Code') {
|
stage('Checkout Source Code') {
|
||||||
steps {
|
steps {
|
||||||
echo "📦 Cloning main application repository..."
|
echo "Cloning main application repository..."
|
||||||
checkout scm
|
checkout scm
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -21,7 +21,7 @@ pipeline {
|
||||||
stage('Build & Push Backend') {
|
stage('Build & Push Backend') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
echo "⚙️ Building backend image..."
|
echo "Building backend image..."
|
||||||
withCredentials([usernamePassword(credentialsId: 'gitops-dockerhub', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
|
withCredentials([usernamePassword(credentialsId: 'gitops-dockerhub', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
|
||||||
sh '''
|
sh '''
|
||||||
docker login -u $DOCKER_USER -p $DOCKER_PASS
|
docker login -u $DOCKER_USER -p $DOCKER_PASS
|
||||||
|
|
@ -40,7 +40,7 @@ pipeline {
|
||||||
stage('Build & Push Frontend') {
|
stage('Build & Push Frontend') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
echo "⚙️ Building frontend image..."
|
echo "Building frontend image..."
|
||||||
withCredentials([usernamePassword(credentialsId: 'gitops-dockerhub', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
|
withCredentials([usernamePassword(credentialsId: 'gitops-dockerhub', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
|
||||||
sh '''
|
sh '''
|
||||||
docker login -u $DOCKER_USER -p $DOCKER_PASS
|
docker login -u $DOCKER_USER -p $DOCKER_PASS
|
||||||
|
|
@ -59,12 +59,12 @@ pipeline {
|
||||||
stage('Update GitOps Repo') {
|
stage('Update GitOps Repo') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
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')]) {
|
withCredentials([usernamePassword(credentialsId: 'gitea-token-gitops', usernameVariable: 'GITEA_USER', passwordVariable: 'GITEA_PASS')]) {
|
||||||
sh '''
|
sh '''
|
||||||
# Install yq kalau belum terpasang
|
# Install yq kalau belum terpasang
|
||||||
if ! command -v yq &> /dev/null; then
|
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
|
wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
|
||||||
chmod +x /usr/local/bin/yq
|
chmod +x /usr/local/bin/yq
|
||||||
fi
|
fi
|
||||||
|
|
@ -75,7 +75,7 @@ pipeline {
|
||||||
cd gitops
|
cd gitops
|
||||||
|
|
||||||
# Update image tag dengan yq
|
# 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 == \\"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
|
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 {
|
post {
|
||||||
success {
|
success {
|
||||||
echo "✅ GitOps update successful — manifests updated in ${DEPLOY_OVERLAY}"
|
echo "GitOps update successful — manifests updated in ${DEPLOY_OVERLAY}"
|
||||||
}
|
}
|
||||||
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