【发布时间】:2020-09-13 22:01:33
【问题描述】:
我目前正在尝试自动增加版本,将 SNAPSHOT 附加到它并提交到使用 GitLab 12.9.2 和 GitLab-Shell 12.0.0 创建给定标签的分支。
我知道,标签(尤其是发布标签)应该是从 master 创建的,但是由于我可能会得到一个开发或其他分支,我想在其上标记提交,所以我想保留能够标记给定的提交、构建、部署相应的工件(到 Nexus)、自动增加版本(例如从 0.1.3 到 0.1.4-SNAPSHOT)和提交到创建标签的分支。
虽然所有其他步骤都有效,但我在最后一步失败了,因为我找不到正确的环境变量,它指的是创建标签的提交(和分支)。
这是 CI 文件的摘录:
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
我得到的错误(在最后一个命令中,如作业的输出控制台中所示):
$ 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>
注意:一切正常,除了提交$CI_COMMIT_REF_NAME 似乎是个坏主意,因为它只包含标签(在上述情况下),但不包含提交(因此分支)标签是从创建的。我在这里谈论这个特殊的价值:
.
我已经阅读了各种其他与主题相关的 SO 问题(例如这个:How do I push to a repo from within a gitlab CI pipeline?),但它们似乎并没有解决我的问题。
使用--points-at 的另一个解决方案似乎很有趣,但我不知道如何以某种方式使用它,这将帮助我解决我的问题。
感谢任何帮助!
【问题讨论】:
标签: git gitlab environment-variables gitlab-ci