Hi, I am trying to create a workflow where when I push a new tag, the pipeline adjusts the README.md file to update the inclusion example automatically. Something similar was working fine for me from the default commit hook, but when I try to use the tag hook I run into issues. The issue I am running from is there appears there is no active repository (there is in the checkout hook). It also appears that fetch does not work, checkout does not work , commit does not work, push does not work. Basically "nothing works" (tm). With a raw git-commit/push the error is "fatal, you are not on a branch", stating a detached head. I have tried get checkout master, which tells me "error: pathspec 'master' did not match any file(s) known to git".
Any advice would be greatly appreciated.
Hi Richard,
Just to give you some context, every step of Pipelines build runs in a Docker container where the repo is cloned, and that container gets destroyed when the step finishes. If the step runs on a branches definition, then only the branch that triggered the build will be cloned with a default depth of 50 (last 50 commits). It is possible to specify a different depth or full depth, see here:
However, when a build runs on a tags definition, that specific tag is cloned. If you expand the Build setup in one of your builds that runs on tags you will see the clone command starts with
GIT_LFS_SKIP_SMUDGE=1 retry 6 git clone --branch="v1.13.0" --depth 50 <....>
where v1.13.0 will be your tag. When the value of the --branch argument is a tag, there are no branches in that clone (the same will occur if you make such a clone locally) and the repo is in a 'detached HEAD' state.
You will need to add commands in the yml file to create a branch, pull any changes, and then make a commit and push.
For example, if the tags are always added to commits of master branch and you want the build to push back to master branch, the script could look as follows:
script:
- git switch -c master
- git pull origin master
- echo " some text " >> test.txt
- git add test.txt
- git commit -m "adding some text to test.txt"
- git push
Kind regards,
Theodora
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.