Search code examples
dockergitlab-cirulessingularity-container

Triggering stage with rules


I developed a gitlab pipeline with several stages and builds, now I would like to be able to specify which builds are going to be executed. Ideally I would like to detect the changes under docker_dir/*, but right now I cannot get code to trigger the build.

.ci_rules:
  rules:
    - if: '$IS_JOB_ON == "TRUE"'
      when: always

.job_template: &start_docker
  variables:
    BUCKET: "ci-jupyterhub-singularity"
  tags:
    - autoscale-large
  rules:
    - !reference [ .ci_rules, rules ]
  script:
    - echo "start job"

build:
  stage: build_docker_image
  <<: *start_docker
  before_script:
    - export IS_JOB_ON="TRUE"

Solution

  • rules: are evaluated at the time the pipeline graph is generated. Because rules: are used to make the pipeline in the first place, you cannot use the output of a variable exported in a job to affect rules: evaluation in the same pipeline.

    However, detecting changes is a builtin rule feature. For example, to trigger a job when any file changes in the docker_dir/ directory (including subdirectories) you can do the following:

    rules:
      - changes:
        - docker_dir/**/*