In my gitlab-ci build, I am generating documentation text files corresponding to the source commits. I would then like to commit these files to the repository so that they will be available for review by developers. The build process also generates executables from source, but those are not added to source control.
I followed the suggestion here to implement the initial commit of the text files: https://forum.gitlab.com/t/how-to-deploy-the-artifact-of-a-ci/38198/3
The relevant lines of my gitlab-ci script are below
- git config --global user.name project_bot
- echo "Committing with token $TOKEN"
- for file in ./*.txt; do echo "*** COMMITTING ${file}"; git add ${file}; git commit ${file} -m "Updated ${file}"; git push --push-option=ci.skip https://project_bot:$TOKEN@our.internal.gitlab/devgroup/project HEAD:${CI_COMMIT_BRANCH}; done
For the initial commit, this went fine, and I received this output (anonymized):
$ for file in ./*.txt; do echo "*** COMMITTING ${file}"; git add ${file}; git commit -m "Updated ${file}"; git push https://project_bot:$TOKEN@our.internal.gitlab/devgroup/project HEAD:${CI_COMMIT_BRANCH}; done
*** COMMITTING ./file1.txt
[detached HEAD 575de7c] Updated ./file1.txt
Subsequent builds, however, fail as shown below:
$ for file in ./*.txt; do echo "*** COMMITTING ${file}"; git add ${file}; git commit -m "Updated ${file}"; git push https://project_bot:$TOKEN@our.internal.gitlab/devgroup/project
*** COMMITTING ./file1.txt
HEAD detached at d2bfb93
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: file2.txt
modified: file3.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
file1.exe
file2.exe
file3.exe
no changes added to commit (use "git add" and/or "git commit -a")
Cleaning up file based variables
00:00
ERROR: Job failed: exit status 1
I am not clear as to why this is failing, but I'm guessing it is because I am attempting to commit a file that has not been changed. Is there a way to only run the commit if the file contents have changed?