I just tried this in production and it works. I have some comments about the dev experience.
include: - template: Code-Quality.gitlab-ci.yml generates a single CQ JSON output job.
Result: OK.
include: - template: Code-Quality.gitlab-ci.yml + copy pasting the entire contents of code_quality from the template + adding the variable REPORT_HTML: html generates, a CQ JSON job and a CQ HTML job.
Result: OK, but copy pasting from a template is undesirable.
Modify the include template to use a YAML anchor like .code_quality_template: &code_quality_template, then the main CQ job in the template would be defined like:
code_quality: <<: *code_quality_template
then to define in the user-defined gitlab-ci.yml:
code_quality_html: variables: REPORT_FORMAT: html artifacts: expire_in: 90 days paths: - gl-code-quality-report.html <<: *code_quality_template
Result: Error, YAML anchors are not preserved across include boundaries, several Issues opened around this and closed wont/fix. Next, trying extends:.
Using extends:
code_quality_json: extends: code_quality artifacts: expire_in: 90 dayscode_quality_html: extends: code_quality artifacts: expire_in: 90 days paths: - gl-code-quality-report.html variables: REPORT_FORMAT: html
Result: Undesirable effect. Three jobs - code_quality from the template, code_quality_json and code_quality_html are run since I would like to override some default settings.
Using extends: and disabling the template code_quality job and re-enabling the user-defined jobs by overriding the rules:
I think this ends up looking like hacky way to get a desirable effect with two jobs, but I don't have a good suggestion on how to make this better. Maybe you might know something that I'm doing wrong?
Update: I think I found the way. The first job definition in the user-defined .gitlab-ci.yml file should have no extends: while overriding any settings and the second job definition should use extends:. No messing with rules:.
code_quality: artifacts: expire_in: 90 dayscode_quality_html: extends: code_quality variables: REPORT_FORMAT: html artifacts: expire_in: 90 days paths: - gl-code-quality-report.html