Skip to content

Add support for CI_COMMIT_REF_NAME variable in includes

Max Woolf requested to merge 331506-mw-add-predefined-variables into master

What does this MR do?

  • Adds the ability to use the $CI_COMMIT_REF_NAME variable in an include block in a CI pipeline.
    • This has the intended side-effect of adding support for merge requests that use compliance frameworks.

Screenshots or Screencasts (strongly suggested)

How to setup and validate locally (strongly suggested)

This is the instructions to set up the compliance-framework specific use-case. It can be used on its own though.

  1. Ultimate only feature
  2. Create a new group.

Set up compliance framework

  1. Within that group, a new project "ComplianceFrameworks".
  2. Create a file to hold the framework config: .gitlab-compliance-ci.yml
stages:
  - test
  - build

compliance_job:
  stage: build
  script:
    - echo "Performing compliance build steps"

include:
  - file: '$CI_CONFIG_PATH' # .gitlab-ci.yml of
    project: '$CI_PROJECT_PATH' # the project currently creating the pipeline
    ref: '$CI_COMMIT_REF_NAME'
  1. In the group settings, create a new compliance framework. Call it whatever you like, and use the new file as the pipeline config.

Set up project

  1. In the same group, create a new project.
  2. In the project settings, set the compliance framework to be the framework created above.
  3. Create a gitlab CI configuration: .gitlab-ci.yml - Something like this...
stages:
  - test

testing:
  stage: test
  script:
    - echo "This is master"

Test it!

  • Run a CI pipeline of master. It should work, and include the compliance pipeline. Note the output: "This is master".
  • Edit .gitlab-ci.yml and update the script to output something different.
  • Commit that change to a different branch and create a merge request.
  • Start a new pipeline for the newly created branch.
  • Note the changed output in the CI log should match the change made.

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Related to #331506 (closed)

Edited by Max Woolf

Merge request reports