Troubleshooting 'replaceImageTag' and 'sed' Command in Pipeline Execution
KarimaFathi opened this issue · 1 comments
During the 'Update Deployment File' stage, 'replaceImageTag' will be updated to 1 after the successful first execution of the pipeline. However, during the second execution, we cannot change it to 2 as 'replaceImageTag' will no longer exist. Therefore, the 'sed' command can alter the build number to 2 instead.
Create a file in spring-boot-app-manifests Directory as build.sh .
Put this contain into build.sh file into -->
#!/bin/bash
BUILD_NUMBER=${BUILD_NUMBER}
let PRE_BUILD=$BUILD_NUMBER-1
sed -i "s/cicd:$PRE_BUILD/cicd:$BUILD_NUMBER/g" java-maven-sonar-argocd-helm-k8s/spring-boot-app-manifests/deployment.yml
make changes in JenkinsFile for last step --->
stage('Update Deployment File') {
environment {
GIT_REPO_NAME = "Jenkins-Zero-To-Hero"
GIT_USER_NAME = "asim0196"
}
steps {
withCredentials([string(credentialsId: 'github', variable: 'GITHUB_TOKEN')]) {
sh '''
git config user.email "asimshaikh113322@gmail.com"
git config user.name "asim0196"
BUILD_NUMBER=${BUILD_NUMBER}
bash java-maven-sonar-argocd-helm-k8s/spring-boot-app-manifests/build.sh
git add java-maven-sonar-argocd-helm-k8s/spring-boot-app-manifests/deployment.yml
git commit -m "Update deployment image to version ${BUILD_NUMBER}"
git push https://${GITHUB_TOKEN}@github.com/${GIT_USER_NAME}/${GIT_REPO_NAME} HEAD:main
'''
}
}
}