Create a publisher plugin allowing to send qualitygate results to the GitLab issues
Current situation
opentf-tools get qualitygate now allows to send the qualitygate results as a note to the related Gitlab MR via the dedicated plugin.
To extend its application, it could be interesting to create an user-configurable orchestrator publisher plugin that can be used in autom context and allows for sending the quality gate results as note a to the related issue.
Desired outcome
Create the tracker publisher plugin that applies the quality gate to the workflows containing specific gitlab/... labels and publishes the results to the GitLab instance, project and issue specified. The results will be published in the same format as the GitLab merge requests (see tools#90 (closed) for details).
Tracker Publisher configuration file
A configuration file containing a list of tracker instances must be provided to the tracker publisher. If the plugin is launched without configuration file, it is disabled.
This configuration file is provided to the plugin via the environment variable TRACKERPUBLISHER_INSTANCES, that takes the configuration file path as value. The configuration file is monitored for changes and reloaded when the changes are detected.
The configuration file has the following structure:
default-instance: first instance
instances:
- name: first instance
endpoint: http://gitlab.example.com
type: gitlab
keep-history: false
token: token
default-qualitygate: my.quality.gate
default-instance and instances are mandatory. instances must contain at least one instance, and each instance on the list must have its name, endpoint, type and keep-history defined. An error message will be issued and the results will not be published if:
a) default-instance is not in the instances list,
b) there are name duplicates in instances.
keep-history indicates if a given quality gate results are kept (true) or updated (false).
type is the tracker type, currently only gitlab is supported.
token is the GitLab token and default-qualitygate is the quality gate applied by default for this instance. Instance's default-qualitygate will be overwritten by the quality gate specified at the workflow level, and when instance and workflow do not provide the quality gate mode, it defaults to strict.
Workflow labels
To be handled by tracker publisher, the workflow metadata section must contain the gitlab/... labels that provide information about the quality gate results publication target.
Assuming tracker publisher is running with previously specified configuration file, the plugin will apply the quality gate job.filter.quality.gate to the test results of the following workflow and send the quality gate response to the GitLab project 48740831 issue 2 as note. The plugin will use the default GitLab instance, i.e. first instance and keep all the previous notes related to the job.filter.quality.gate, thus overwriting the keep-history parameter specified at the instance level.
metadata:
name: Running GitlabPublisher
labels:
gitlab/project-id: '48740831' #or gitlab/project-path: 'group/project'
gitlab/issue-iid: '42'
gitlab/instance: default
gitlab/keep-history: true
qualitygate-mode: job.filter.quality.gate
jobs:
gitlab-publisher-test:
runs-on: ['linux', 'robotframework']
steps:
- uses: robotframework/execute@v1
with:
test: test/path.robot
working-directory: /home/user/tests
There are two mandatory labels: gitlab/project-id OR gitlab/project-path and gitlab/issue-iid (or gitlab/mr-iid, which is also allowed as publishing target). If one of them is missing, the results will not be published.
gitlab/instance contains the name of the instance from the plugin configuration file to send the results to. If gitlab/instance is set to default or if it is omitted, the default-instance from the configuration file will be used.
gitlab/keep-history, if set, overwrites the keep-history value at the instance level.
qualitygate-mode, if set, overwrites the default-qualitygate of the specified instance.
