I need to take certain actions during a Git CI/CD pipeline under the following conditions:
- A new tag has been created
- The branch name is 'develop'
Tags are associated with commits, not branches, so the branch name is not included in the CI variables. One can calculate it from the command line by doing: (the tag name is test8)
$ git branch --remote --contains test8
origin/HEAD -> origin/develop
origin/develop
Unfortunately, Git is not installed on the runner so attempting to execute the above command in the pipeline results in "git not found". I installed Git during the pipeline run, and the install works, but the above command returns nothing after the install. I assume it's because the Git install and the repository are not associated somehow, but I've been wrong before.
Here is the script that is trying to determine the branch name:
# branch name not included in tag data, so compute it
before_script:
- CI_INITIAL_TAGGED_BRANCH=""
- if [ "${CI_COMMIT_TAG}" ]; then CI_INITIAL_TAGGED_BRANCH="$(git branch --remote --contains ${CI_COMMIT_TAG})"; fi
Here is the error:
$ if [ "${CI_COMMIT_TAG}" ]; then CI_INITIAL_TAGGED_BRANCH="$(git branch --remote --contains ${CI_COMMIT_TAG})"; fi
'[' test8 ]
git branch --remote --contains test8
1229/scripts-2290-112564/step_script: eval: line 156: git: not found
Is it possible to determine the branch from whence a tag cometh during a CI/CD pipeline run?