I have enabled automatic release generation via the GitLab CI/CD. I am using something like this:
curl --header "Content-Type: application/json" --header "PRIVATE-TOKEN: $GITLAB_ACCESS_TOKEN" \
--data "{ \
\"name\": \"$GV_SEMVER\", \
\"tag_name\": \"$GV_SEMVER\", \
\"ref\": \"$CI_COMMIT_SHA\", \
\"assets\": { \"links\": [ \
{\"name\": \"File\", \"url\": \"https://download.example.com/package-$SEMVER.zip\", \"filepath\": \"/package.zip\", \"link_type\": \"other\"}
] } }" \
--request POST "$CI_API_V4_URL/projects/$CI_PROJECT_ID/releases"
The GITLAB_ACCESS_TOKEN
is injected properly and it creates a tag and generates the release. Although this is fine, but the creation of the tag triggered a new pipeline again.
I also tried to use the following approach (it doesn't specify the commit SHA during the API request):
git tag $GV_SEMVER
git push --push-option=ci.skip --tags http://root:$GITLAB_ACCESS_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git HEAD:$CI_COMMIT_BRANCH
curl --header "Content-Type: application/json" --header "PRIVATE-TOKEN: $GITLAB_ACCESS_TOKEN" \
--data "{ \
\"name\": \"$GV_SEMVER\", \
\"tag_name\": \"$GV_SEMVER\", \
\"assets\": { \"links\": [ \
{\"name\": \"File\", \"url\": \"https://download.example.com/package-$SEMVER.zip\", \"filepath\": \"/package.zip\", \"link_type\": \"other\"}
] } }" \
--request POST "$CI_API_V4_URL/projects/$CI_PROJECT_ID/releases"
The git push
pushes the new tag to GIT and the ci.skip
option prevents a new CI build. But when I have a longer pipeline, then some people may have pushed data and the git push
fails. I would rather use the API, but I need a way to disable the CI build.