I am currently trying to auto-increment the version, append SNAPSHOT
to it and commit to the branch the given tag was created from using GitLab 12.9.2 and GitLab-Shell 12.0.0.
I know, that tags (especially release-tags) are supposed to be created from master, but since I might be getting a develop- or other branches, that I'd like to tag commits on, I wanted to keep the ability to tag a given commit, build, deploy the corresponding artifact (to Nexus), auto-increment the version (e.g. from 0.1.3
to 0.1.4-SNAPSHOT
) and commit this to the branch the tag has been created from.
While all other steps work, I fail at the last one, because I cannot find the proper environment variable, which refers to the commit (and branch) the tag was created from.
Here is an excerpt from the CI-file:
build-release:
extends: .build-template
only:
- tags
before_script:
# Setup git
- git config http.sslVerify false
- git config user.email "git-bot@base/gitlab"
- git config user.name "$GIT_CI_USER"
- git remote set-url origin https://$GIT_CI_USER:$GIT_CI_PASSWORD@base/gitlab/development/particles/particles-front.git
- git fetch
# - git config http.sslCAInfo /etc/gitlab-runner/certs/base.crt ?
# - git config http.sslCert /etc/gitlab-runner/certs/base.crt ?
- cd $CI_BUILDS_DIR/$SUB_PATH
# Install node_modules
- npm install
# Show versions
- node --version
- npm --version
- npm run ng version
# Save version for artifact-name
- echo -n $CI_COMMIT_TAG > $CI_BUILDS_DIR/$SUB_PATH/version
# Set version back via npm in order to display it possibly on the user interface
- npm version $(cat $CI_BUILDS_DIR/$SUB_PATH/version)
after_script:
# Auto-Increment (patch-)version, append SNAPSHOT, commit & push
- git checkout $CI_COMMIT_REF_NAME
- cd $CI_BUILDS_DIR/$SUB_PATH
- cat $CI_BUILDS_DIR/$SUB_PATH/version
- npm version patch | cut -c 2-30 | tr -d '\n' > $CI_BUILDS_DIR/$SUB_PATH/version
- echo -n -SNAPSHOT >> $CI_BUILDS_DIR/$SUB_PATH/version
- npm version $(cat $CI_BUILDS_DIR/$SUB_PATH/version)
- npm run prestart
- git add ./package*.json ./src/_versions.ts
- git status -sb
- git commit -m "New Snapshot ($(cat $CI_BUILDS_DIR/$SUB_PATH/version))"
- git push
The error I am getting (at the last command, as seen in the output console of the job):
$ git push
fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use
git push origin HEAD:<name-of-remote-branch>
Note: everything works fine except that committing to a $CI_COMMIT_REF_NAME
seems to be a bad idea, because it only contains the tag (in the case above), but not the commit (and therefore the branch) the tag was created from. I am talking about this particular value here:
.
I have read various other topic-related SO questions (such as this one: How do I push to a repo from within a gitlab CI pipeline?), but they don't seem to solve my problem.
Another solution using --points-at
seems interesting, but I do not know how to use it in a manner, that'd help me solve my problem.
Any help is appreciated!