Requirement: I've an Java Project which reads excel and updates the same excel after validation. On the build run, it all happens. Now, I've to use the GitLab and Jenkins for it. My code is on GitLab on which I've configured the webhook to run the build.
Issue: After the build, the excel gets updated in Jenkins workspace but I want to push it to GitLab as well. If I do direct push from shell, it runs in loop always. So, I'm not to write the perfect shell for git commands. Can you please help in editing it.
I've tried putting the git commands in different conditions but nothing helped. Below is my shell
#!/bin/bash +x
echo =================== Starting Job =========================
git config user.name "Tarun"
git config user.email tarun.verma2710@gmail.com
state=`git status`
echo *******Status Start*********
echo ${state}
echo *******Status End*********
git pull origin master
git checkout master
git add .
git commit -m "Jenkins Checkin"
if [[ ${state} == *"no changes added to commit"* ]]; then
echo "changes not present"
#git pull origin master
else
echo "changes present"
git push -u --force origin master
fi
echo =================== Shutting Job ==========================
Actual output :
=================== Starting Job =========================
2019-10-01 15:20:59 INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Shutdown initiated...
*******Status Start*********
# HEAD detached at a4c555f # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: spring-boot-automation-tool/excels/QuickActionImplExcel.xlsx # no changes added to commit (use "git add" and/or "git commit -a")
*******Status End*********
2019-10-01 15:20:59 INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Shutdown completed.
From gitlab.corp.amdocs.com:TARUNVE/crm-bpt-automation-tool
* branch master -> FETCH_HEAD
Already up-to-date.
error: Your local changes to the following files would be overwritten by checkout:
spring-boot-automation-tool/excels/QuickActionImplExcel.xlsx
Please, commit your changes or stash them before you can switch branches.
Aborting
[detached HEAD 85e27cd] Jenkins Checkin
1 file changed, 0 insertions(+), 0 deletions(-)
rewrite spring-boot-automation-tool/excels/QuickActionImplExcel.xlsx (99%)
changes not present
=================== Shutting Job ==========================
Expected Output: I want to have smooth check-in , once the build is complete, it is updated in GitLab as well. And also check-in should happen to GitLab only if changes are present in Excel.