Hello,
I’m desperately trying to make a CI script discovering which branch (or branches) a tagged commit is referring to. I can’t use the $CI_COMMIT_BRANCH
variable in a job that is triggered by tagging a commit, but I do need this job’s script to discover the name of the branch (or branches) that was (or were) changed by this commit.
So, long story short, I need to do something like that: git branch --contains "$(git for-each-ref | sed -r -n "s#^([0-9a-f]{40})[[:space:]]+tag[[:space:]]+refs/tags/${CI_COMMIT_TAG}#\1#gp")" | sed -r 's/^\*[[:space:]]//'
, but my problem is that the HEAD
is being detached on the start of the job.
I tried to understand how to prevent that and found several pieces of advice to change the GIT_STRATEGY
variable to clone
. If I’m not wrong, the point is that the job runner performs fetch
instead of clone
, so merging doesn’t happen. I’m not sure that I really understand it absolutely clear, but I hope that I’m not totally wrong.
So, I try to add the GIT_STRATEGY
variable with the clone
value to my job configuration. The CI configuration looks like as follows:
bar:
stage: foo
variables:
GIT_STRATEGY: clone
CI_DEBUG_TRACE: "true"
script:
- git branch -a
But it doesn’t seem to perform the clone
command, it still sticks to fetch
: bar (#3201428240) · Jobs · Volodymyr Melnyk / sample-git-strategy · GitLab, so the git branch -a
reports that the HEAD
is still detached (so sad).
I’ve created a sample minimal project to demonstrate this issue, here it is: Volodymyr Melnyk / sample-git-strategy · GitLab
Would anyone be so kind as to help me to understand what I’m doing wrong and how to find out which branch is (or branches are) affected by the commit?
Thanks in advance!