Jobs in included file do not run

GitLab doesn’t run run jobs defined in my included files.

We are trying to set up global rules for all our projects and I can’t seem to get the jobs inside the included .yml to execute. I only get the single job inside my .gitlab-ci.yml file to execute.

Here is the .gitlab-ci.yml file:

include:
  # A local configuration file is required for the default-ci.yml to work.
  # The local include must always precede the bri000-cicd include
  - local: 'ci-variables.yml'

  # Include from the bri000-cicd repository
  - project: 'briowireless/bri/bri000/bri000-cicd'
    # The ref below can be a branch name, a tag or a commit SHA-1.
    ref: bugfix/default-branch
    file: 'default-ci.yml'

# All checks are part of the default-ci.yml file. Only the build stages are required.
stages:
  # Do not remove the prep and check stages as they are needed for the included default Brio rules
  - prep
  - check
  - build


default:
  before_script:
    # Fetch the submodules manually since it can't be done with the submodule strategy
    - git submodule sync --recursive
    - git submodule update --init --recursive


build-code:
  stage: build
  script:
    - echo "Building application"

Here is my included file:

workflow:
  rules:
  # Workflow rules are assessed in sequential order (ie. GitLab checks the rules starting from the top until a rule is true)
  # The rules allow pipelines to run in multiple conditions:
  # We always run pipelines for merge requests
  # We never run pipelines for branches that have an open merge request (removes duplicates)
  # We can start pipelines manually if the branch name starts with 'wip/' (regardless of MR or not)
  # We always run pipelines for all other branches that do not fall in the conditions above
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
    - if: $CI_COMMIT_BRANCH == 'initial'
      when: never
    - if: $CI_COMMIT_BRANCH =~ '/wip\/.*/'
      # Allows wip branch pipelines to not be run (prevents unwanted errors)
      when: never
    - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
      when: never
    - if: $CI_COMMIT_BRANCH


stages:
  - prep
  - check


variables:
  COMMIT_SHA: $CI_COMMIT_SHA
  # This is required because the submodules are handled by the GitLab runners.
  # The GitLab runners don't work with ssh clones, therefore, we must fetch
  # the submodules in the recipes themselves.
  # See the link below for more info:
  # https://gitlab.com/gitlab-org/gitlab-runner/-/issues/2075
  GIT_SUBMODULE_STRATEGY: none

# Get docker image which contains all required tools for quality checks
image: <path to our registry image>


prepare files:
  stage: prep
  rules:
    - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
      variables:
        # Override the default value
        COMMIT_SHA: $CI_MERGE_REQUEST_TARGET_BRANCH_SHA
  script:
    # Generate list of files (this will be used by the other CI checks)
    # Do some stuff with the $COMMIT_SHA variable
  artifacts:
    paths:
      - ci.txt
  tags:
    - lint

ciformat:
  stage: check
  rules:
    - if: $ENABLE_CLANGFORMAT != "YES"
      when: never
  needs:
    - job: "prepare files"
  script:
    - echo "Check clang-format"
    - FILES="$(cat ci.txt)"
    - clang-format-13 -i -style=file $FILES -n -Werror --ferror-limit=1
  tags:
    - lint

cidoc:
  stage: check
  rules:
    - if: $ENABLE_DOXYGEN != "YES"
      when: never
  needs:
    - job: "prepare files"
  script:
    - echo "Check doxygen"
    - mkdir -p ci/doxyten
    - touch ci/doxygen/warnings.log
    - chmod +x ci/scripts/run_doxygen.sh
    - ci/scripts/run_doxygen.sh -i ci.txt
  artifacts:
    paths:
      - ci/doxygen/warnings.log
      - ci/doxygen/html
  tags:
    - lint

What am I missing?

Thanks for the help
Michel

Hi @msolecki

problem is with the rules definitions in the included jobs. There must be at least one rule which evaluate as True in order for the Job to be added to the pipeline:

The job is added to the pipeline:
- If an if, changes, or exists rule matches and also has when: on_success (default), when: delayed, or when: always.
- If a rule is reached that is only when: on_success, when: delayed, or when: always.

The job is not added to the pipeline:
- If no rules match.
- If a rule matches and has when: never.

In your case when you do not want to add the job in a specific case, just add another rule (at the end) with simply - when: on_success

1 Like

Hi @balonik

Thanks for the answer, but I am not sure I understand which rule(s) don’t match.

I copied the first example from the GitLab workflow help page (I added the initial and wip/* rules, but it doesn’t work with the “original” version that I copied)

I have a second question related to this issue:
The build-code job which is in the .gitlab-ci.yml file is the only job that runs in the pipeline. Does that mean that the workflow rules apply only to the jobs in the included file?

Thank you for your help
Michel

OK, so I figured out my problem and what you meant by having at least one rule that matches.

My problem was in the prepare files job (in the include) which didn’t run because I had an if clause. My understanding was that the if could be used to change the default value of a variable, but I was not aware that the if would also affect the decision whether to run the job or not.

Thank you very much for the help!

Michel