Skip to content

Add ref param to project level ci/lint

Thad Craft requested to merge thadc23/gitlab:lint_branch_context into master

What does this MR do and why?

Fixes #320778 (closed)

This merge request adds a ref parameter to the api/v4/projects/:id/ci/lint endpoint allowing for a git ref to be passed in to set a context for where to dry run the pipeline.

How to set up and validate locally

Assuming that you have the Gitlab Development Kit up and running with the initial data load.

  1. Create a test.sh script with the following content:
#! /bin/bash

jq --null-input --arg yaml "$(<local.yml)" '.content=$yaml' \
| curl -X POST "http://gdk.test:3000/api/v4/projects/6/ci/lint?dry_run=true&include_jobs=true&ref=remove-from" \
--header 'Content-Type: application/json' \
--header "PRIVATE-TOKEN: $LOCAL_GITLAB_TOKEN" \
--data @- | jq

jq --null-input --arg yaml "$(<local.yml)" '.content=$yaml' \
| curl -X POST "http://gdk.test:3000/api/v4/projects/6/ci/lint?dry_run=true&include_jobs=true" \
--header 'Content-Type: application/json' \
--header "PRIVATE-TOKEN: $LOCAL_GITLAB_TOKEN" \
--data @- | jq
  1. Create a gitlab ci file called local.yml:
another_test:
  stage: test
  script:
    - echo 2

one_more:
  stage: test
  script:
    - echo 3
  rules:
    - if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
      when: never
    - when: manual
  1. Run local.sh and check the output to see that the first run returns both jobs because the ref param is set to a non default branch. The second output has only 1 job since the ref is not set, thus reverts back to the default branch.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Thad Craft

Merge request reports