Add PublishToCatalog command
What does this MR do and why?
In this change, we are moving the logic of publishing CI components
into release-cli
. (gitlab#442785 (closed))
With this new command;
release-cli publish-to-catalog --version 3.0.0
release-cli
will fetch the components from the current project,
parses the component names and their spec
s, and sends a request to
the /api/v4/projects/:PID/catalog/publish
with a body.
How it works
- If a CI job has the
release
keyword, GitLab adds arelease
script to the job when sending it to Runner. - If the project is not a Catalog resource, the script only consists of
release-cli create --name=abc tag_name=1.0.0 ...
. - If the project is a Catalog resource, the script also has
release-cli publish-to-catalog --version=1.0.0
. - When the job runs, it's required that the job environment has the
release-cli
. (Runner generally fetchesregistry.gitlab.com/gitlab-org/release-cli:latest
) -
release-cli
first creates a "release" with the tag "1.0.0" (POST /projects/:id/releases
). - Then, it publishes the version to the CI Catalog (
POST /projects/:id/catalog/publish
).
Reproduce
-
We need gitlab!167883 (merged) and the feature flag
ci_release_cli_catalog_publish_option
enabled in our local development environment. -
An example
.gitlab-ci.yml
for a component project;
create-release:
rules:
- if: $CI_COMMIT_TAG =~ /\d+/
script: echo "Creating release $CI_COMMIT_TAG"
release:
tag_name: $CI_COMMIT_TAG
description: "Release $CI_COMMIT_TAG of components repository $CI_PROJECT_PATH"
- An example component template YAML file;
- Run a pipeline and see the result;
Checklist
-
I added tests -
Green pipeline -
Assign to reviewer
Edited by Furkan Ayhan