Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Troubleshooting 'replaceImageTag' and 'sed' Command in Pipeline Execution #94

Open
KarimaFathi opened this issue Oct 18, 2023 · 1 comment

Comments

@KarimaFathi
Copy link

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.

@asim0196
Copy link

asim0196 commented Nov 7, 2023

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
'''
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants