5

I want that the CI only execute this job if I am on master, merge request, scheduled pipeline OR if the variable COVERAGE_TEST is equal to ON:

c++TestCoverage:
  stage: analysis
  script: "./ciScripts/testCoverageScript.sh"
  tags:
    - framework
  dependencies:
    - c++Build
  variables:
    GIT_STRATEGY: fetch
  artifacts:
    paths:
      - ./build/test_coverage/
    expire_in: 1 week
    when: on_success

I tried adding the next lines:

only:
  refs:
    - master
    - merge_requests
    - schedule
  variables:
    - $COVERAGE_TEST == "ON"

But the result is actully -> If ((Master || MergeRequest || ScheduledPipeline) && COVERAGE_TEST == ON)


I also tried with:

only:
  variables:
    - $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"
    - $CI_PIPELINE_SOURCE == 'merge_request_event'
    - $CI_PIPELINE_SOURCE == 'schedule'
    - $COVERAGE_TEST == "TRUE" 

but CI_PIPELINE_SOURCE == 'merge_request_event' does not work as I want because If I have the branch in merge request and I push some changes the value of CI_PIPELINE_SOURCE is push


Is there a way to do it?

1 Answer 1

2

You need to use rules and if keywords to test all variables values and put OR between the tests.

Correct configuration in your case should be :

  rules:
    - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" || $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_PIPELINE_SOURCE == "schedule" || $COVERAGE_TEST == "TRUE"'
      when: always
Sign up to request clarification or add additional context in comments.

3 Comments

Yes, but that would do the same as what I put in the last option I tried. My problem with that one is that $CI_PIPELINE_SOURCE == "merge_request_event" is not true every time I push in branch that is in a merge request. Do you know any variable that does exactly that?
Sorry, I don't see the problem. $CI_PIPELINE_SOURCE is set to "merge_request_event" only when a merge request is opened.
Yes, what I would like is variable that tells me every time a push I donde to a branch that is in a merge request. In the case I put in the question ‘only: refs: merge_request’ does exactly that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.