Reputation: 35785
Currently, our developers create release versions of Java artifacts by manually triggering a process that takes the main
branch and builds a release version through Maven.
I wonder how I should implement this in GitLab CI. In GitHub Actions, I could, e.g., write a "release" workflow file and then run it manually through the Actions tab.
In GitLab CI, I found that one could run jobs manually, but jobs are just part of a pipeline. Furthermore, you can start pipeline runs manually, but this would trigger the standard pipeline (SNAPSHOT build, etc.). One could use a variable RELEASE, but letting the user input "RELEASE=true" for every release build seems cumbersome.
Is there any straightforward way to solve this?
Upvotes: 1
Views: 4002
Reputation: 40861
GitLab's release-cli
is made for this use-case. It is documented in create a release by using a cicd job. The release:
key can be used for easily configuring the job to invoke release-cli with corresponding options.
It is a common practice to create releases using a tag -- that way release jobs only run when a tag is deliberately pushed. You can use something like rules:
- if: $CI_COMMIT_TAG
.
release_job:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
rules:
- if: $CI_COMMIT_TAG # Run this job when a tag is created manually
script:
- echo "running release_job"
release:
name: 'Release $CI_COMMIT_TAG'
description: 'Created using the release-cli $EXTRA_DESCRIPTION' # $EXTRA_DESCRIPTION must be defined
tag_name: '$CI_COMMIT_TAG' # elsewhere in the pipeline.
ref: '$CI_COMMIT_TAG'
milestones:
- 'm1'
- 'm2'
- 'm3'
released_at: '2020-07-15T08:00:00Z' # Optional, is auto generated if not defined, or can use a variable.
assets: # Optional, multiple asset links
links:
- name: 'asset1'
url: 'https://example.com/assets/1'
- name: 'asset2'
url: 'https://example.com/assets/2'
filepath: '/pretty/url/1' # optional
link_type: 'other' # optional
You can, of course, also just create a job with a script:
that invokes release-cli
.
You could also control your job other ways, like with when: manual
so that releases are only created by deliberate action on pipelines for the main branch.
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
when: manual
Upvotes: 3