[英]Gitlab CI/CD auto tagging release
我試圖讓我的 GitLab 管道自動標記master
分支,但沒有運氣。
由於項目是composer package,所以我要做的是從composer.json
文件中獲取版本號,將其存儲在一個變量中,然后將此變量與ZBA9F11ECC3497D9993B933FDC2BD61EZ一起使用來標記分支。
這是我的.gitlab-ci.yml
中的管道作業部分:
tagging:
stage: publish
image: alpine
only:
- master
script:
- version=$(cat composer.json | grep version | grep -Eo "[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+")
- git tag "$(version)"
- git push --tags
我實際上無法說出問題所在,因為在 GitLab 作業 output 中沒有顯示 output,如下圖所示
好的,不知道為什么這不起作用,但我發現我在第一個 grep 命令中寫了Version
(大寫 V)而不是version
:這不應該是問題的原因,因為在本地相同的命令管道返回 0 但不是錯誤。
我不想像@davide-madrisan 建議的那樣在管道作業映像上安裝額外的 cli 命令,因為我想讓它盡可能簡單。
此外,我發現這個有趣的 gitlab repo 正是我所需要的:
https://gitlab.com/guided-explorations/gitlab-ci-yml-tips-tricks-and-hacks/commit-to-repos-during-ci/commit-to-repos-during-ci
所以最后我想出了這個管道工作:
tagging:
stage: publish
only:
- master
script:
- git config --global user.name "${GITLAB_USER_NAME}"
- git config --global user.email "${GITLAB_USER_EMAIL}"
- tag=$(cat composer.json | grep version | grep -Eo "[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+")
- git tag "$tag"
- git push --tags http://root:$ACCESS_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git HEAD:master
我只需要創建一個個人訪問令牌並使用 git 憑據添加樹管道變量來創建標簽並將其從管道內推送到主分支,但它現在實際上可以工作了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.