Allow to post the qualitygate result as a comment to a Gitlab MR
Current situation
We need to allow to post the opentf-ctl get qualitygate
result as a note to a related GitLab MR from a GitLab pipeline.
Desired outcome
Create, for the get qualitygate
command, the new option --plugin
, that allows to specify GitLab instance URL, related project ID, merge request IID and GitLab token (if necessary).
Create the plugin that will send the qualitygate results to the instance, project and merge request specified in the --plugin
option.
The --plugin
option accepts the following parameters:
-
gitlab:server
(URL of the GitLab instance) -
gitlab:project
(GitLab project ID) -
gitlab:mr
(GitLab MR IID) -
gitlab:issue
(Gitlab issue IID) -
gitlab:keep-history
(boolean) - [
gitlab:token
] (GitLab authentication token)
keep-history
, server
, project
and mr
or issue
are mandatory. If not specified from a command line, the results will not be published.
NB: At the same time, there is no need to specify server
, project
and mr
if the command is used within a GitLab merge request pipeline. Their values will be retrieved automatically from $CI_SERVER_URL, $CI_MERGE_REQUEST_PROJECT_ID, $CI_MERGE_REQUEST_IID predefined variables.
If keep-history
is true
, all results sent to a specific merge request are kept. Otherwise, the last results of a given quality gate will be overwritten.
Example
Assuming successfully completed workflow {workflow_id}, the following command from command line:
opentf-ctl get qualitygate {workflow_id} -m quality.gate \
--plugin gitlab:server={GitLab instance URL} \
--plugin gitlab:project={project ID} \
--plugin gitlab:mr={merge request IID} \
--plugin gitlab:token={token} --plugin gitlab:keep-history=true
or the following command defined in a GitLab merge request pipeline (defined in .gitlab-ci.yml
):
opentf-ctl get qualitygate {workflow_id} -m quality.gate \
--plugin gitlab:token={token} \
--plugin gitlab:keep-history=true
must, besides displaying the quality gate results, attach them to the related merge request as a note:
If the quality gate result is SUCCESS
or NOTEST
, the "Rules summary" section is collapsed.