fix: checkout application repo stage
This commit is contained in:
parent
0767b42851
commit
5d59eeb6ba
|
|
@ -40,35 +40,39 @@ pipeline {
|
||||||
|
|
||||||
stage('Checkout Application Repo') {
|
stage('Checkout Application Repo') {
|
||||||
steps {
|
steps {
|
||||||
checkout scm
|
dir('app') {
|
||||||
|
checkout scm
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Build and Push Docker Image') {
|
stage('Build and Push Docker Image') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
dir('app') {
|
||||||
def tag = params.IMAGE_TAG ?: "build-${env.BUILD_NUMBER}"
|
script {
|
||||||
echo "Building and pushing image with tag: ${tag}"
|
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')]) {
|
withCredentials([usernamePassword(credentialsId: env.DOCKER_CRED_ID, usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
|
||||||
sh """
|
sh """
|
||||||
echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin
|
echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin
|
||||||
docker build -t ${REGISTRY}/${APP_NAME}-be:${tag} ./backend
|
docker build -t ${REGISTRY}/${APP_NAME}-be:${tag} ./backend
|
||||||
docker build -t ${REGISTRY}/${APP_NAME}-fe:${tag} ./frontend
|
docker build -t ${REGISTRY}/${APP_NAME}-fe:${tag} ./frontend
|
||||||
docker push ${REGISTRY}/${APP_NAME}-be:${tag}
|
docker push ${REGISTRY}/${APP_NAME}-be:${tag}
|
||||||
docker push ${REGISTRY}/${APP_NAME}-fe:${tag}
|
docker push ${REGISTRY}/${APP_NAME}-fe:${tag}
|
||||||
docker logout
|
docker logout
|
||||||
"""
|
"""
|
||||||
|
}
|
||||||
|
|
||||||
|
env.IMAGE_TAG_FINAL = tag
|
||||||
}
|
}
|
||||||
|
|
||||||
env.IMAGE_TAG_FINAL = tag
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Checkout Manifest Repo') {
|
stage('Checkout Manifest Repo') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
dir('manifest') {
|
||||||
checkout([$class: 'GitSCM',
|
checkout([$class: 'GitSCM',
|
||||||
branches: [[name: env.BRANCH]],
|
branches: [[name: env.BRANCH]],
|
||||||
userRemoteConfigs: [[url: env.MANIFEST_REPO, credentialsId: env.MANIFEST_CRED_ID]]
|
userRemoteConfigs: [[url: env.MANIFEST_REPO, credentialsId: env.MANIFEST_CRED_ID]]
|
||||||
|
|
@ -79,29 +83,33 @@ pipeline {
|
||||||
|
|
||||||
stage('Update Image Tags in Manifests') {
|
stage('Update Image Tags in Manifests') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
dir('manifest') {
|
||||||
echo "Updating manifests to tag: ${env.IMAGE_TAG_FINAL}"
|
script {
|
||||||
|
echo "Updating manifests to tag: ${env.IMAGE_TAG_FINAL}"
|
||||||
|
|
||||||
sh """
|
sh """
|
||||||
yq e -i '.images[] |= (.newTag = "${env.IMAGE_TAG_FINAL}")' base/kustomization.yaml || true
|
yq e -i '.images[] |= (.newTag = "${env.IMAGE_TAG_FINAL}")' base/kustomization.yaml || true
|
||||||
|
|
||||||
yq e -i '.spec.template.spec.containers[0].image = "${REGISTRY}/${APP_NAME}-be:${env.IMAGE_TAG_FINAL}"' base/backend-deployment.yaml
|
yq e -i '.spec.template.spec.containers[0].image = "${REGISTRY}/${APP_NAME}-be:${env.IMAGE_TAG_FINAL}"' base/backend-deployment.yaml
|
||||||
yq e -i '.spec.template.spec.containers[0].image = "${REGISTRY}/${APP_NAME}-fe:${env.IMAGE_TAG_FINAL}"' base/frontend-deployment.yaml
|
yq e -i '.spec.template.spec.containers[0].image = "${REGISTRY}/${APP_NAME}-fe:${env.IMAGE_TAG_FINAL}"' base/frontend-deployment.yaml
|
||||||
"""
|
"""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Commit & Push Manifest Updates') {
|
stage('Commit & Push Manifest Updates') {
|
||||||
steps {
|
steps {
|
||||||
withCredentials([usernamePassword(credentialsId: env.MANIFEST_CRED_ID, usernameVariable: 'GIT_USER', passwordVariable: 'GIT_PASS')]) {
|
dir('manifest') {
|
||||||
sh """
|
withCredentials([usernamePassword(credentialsId: env.MANIFEST_CRED_ID, usernameVariable: 'GIT_USER', passwordVariable: 'GIT_PASS')]) {
|
||||||
git config user.email "jenkins@local"
|
sh """
|
||||||
git config user.name "jenkins"
|
git config user.email "jenkins@local"
|
||||||
git add -A
|
git config user.name "jenkins"
|
||||||
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})
|
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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue