fix: checkout application repo stage
This commit is contained in:
parent
cf45ceb5b0
commit
dee7e6b12b
|
|
@ -5,7 +5,6 @@ pipeline {
|
|||
REGISTRY = "docker.io/adelyao"
|
||||
APP_NAME = "employee"
|
||||
MANIFEST_REPO = "https://git.winteraccess.id/adel/Employee-manifest.git"
|
||||
APP_REPO = "https://git.winteraccess.id/adel/Employee-app.git"
|
||||
MANIFEST_CRED_ID = "GIT_CRED_ID"
|
||||
DOCKER_CRED_ID = "DOCKER_CRED_ID"
|
||||
BRANCH = "main"
|
||||
|
|
@ -17,9 +16,10 @@ pipeline {
|
|||
|
||||
stages {
|
||||
|
||||
stage('Clean Workspace') {
|
||||
stage('Prepare Workspace') {
|
||||
steps {
|
||||
cleanWs()
|
||||
checkout scm // ✅ otomatis clone repo Gitea tempat Jenkinsfile berada
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -38,36 +38,24 @@ pipeline {
|
|||
}
|
||||
}
|
||||
|
||||
stage('Checkout Application Repo') {
|
||||
stage('Build and Push Docker Images') {
|
||||
steps {
|
||||
dir('app') {
|
||||
git branch: env.BRANCH,
|
||||
url: env.APP_REPO,
|
||||
credentialsId: env.MANIFEST_CRED_ID
|
||||
}
|
||||
}
|
||||
}
|
||||
script {
|
||||
def tag = params.IMAGE_TAG ?: "build-${env.BUILD_NUMBER}"
|
||||
echo "Building and pushing image with tag: ${tag}"
|
||||
|
||||
stage('Build and Push Docker Image') {
|
||||
steps {
|
||||
dir('app') {
|
||||
script {
|
||||
def tag = params.IMAGE_TAG ?: "build-${env.BUILD_NUMBER}"
|
||||
echo "Building and pushing image with tag: ${tag}"
|
||||
|
||||
withCredentials([usernamePassword(credentialsId: env.DOCKER_CRED_ID, usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
|
||||
sh """
|
||||
echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin
|
||||
docker build -t ${REGISTRY}/${APP_NAME}-be:${tag} ./employee-be
|
||||
docker build -t ${REGISTRY}/${APP_NAME}-fe:${tag} ./employee-fe
|
||||
docker push ${REGISTRY}/${APP_NAME}-be:${tag}
|
||||
docker push ${REGISTRY}/${APP_NAME}-fe:${tag}
|
||||
docker logout
|
||||
"""
|
||||
}
|
||||
|
||||
env.IMAGE_TAG_FINAL = tag
|
||||
withCredentials([usernamePassword(credentialsId: env.DOCKER_CRED_ID, usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
|
||||
sh """
|
||||
echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin
|
||||
docker build -t ${REGISTRY}/${APP_NAME}-be:${tag} ./employee-be
|
||||
docker build -t ${REGISTRY}/${APP_NAME}-fe:${tag} ./employee-fe
|
||||
docker push ${REGISTRY}/${APP_NAME}-be:${tag}
|
||||
docker push ${REGISTRY}/${APP_NAME}-fe:${tag}
|
||||
docker logout
|
||||
"""
|
||||
}
|
||||
|
||||
env.IMAGE_TAG_FINAL = tag
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -77,7 +65,10 @@ pipeline {
|
|||
dir('manifest') {
|
||||
checkout([$class: 'GitSCM',
|
||||
branches: [[name: env.BRANCH]],
|
||||
userRemoteConfigs: [[url: env.MANIFEST_REPO, credentialsId: env.MANIFEST_CRED_ID]]
|
||||
userRemoteConfigs: [[
|
||||
url: env.MANIFEST_REPO,
|
||||
credentialsId: env.MANIFEST_CRED_ID
|
||||
]]
|
||||
])
|
||||
}
|
||||
}
|
||||
|
|
@ -108,7 +99,7 @@ pipeline {
|
|||
git add -A
|
||||
git diff --staged --quiet || (git commit -m "chore: update image to ${env.IMAGE_TAG_FINAL}" && git push https://${GIT_USER}:${GIT_PASS}@${env.MANIFEST_REPO.replace('https://', '')} ${env.BRANCH})
|
||||
"""
|
||||
echo "Manifest repo updated successfully"
|
||||
echo "✅ Manifest repo updated successfully"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -123,10 +114,10 @@ pipeline {
|
|||
|
||||
post {
|
||||
success {
|
||||
echo "GitOps pipeline completed successfully!"
|
||||
echo "🎉 GitOps pipeline completed successfully!"
|
||||
}
|
||||
failure {
|
||||
echo "Pipeline failed. Check previous logs."
|
||||
echo "❌ Pipeline failed. Check previous logs."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue