Skip to content
GitLab
Next
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • GitLab GitLab
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 44,758
    • Issues 44,758
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
    • Requirements
  • Merge requests 1,331
    • Merge requests 1,331
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Metrics
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • GitLab.orgGitLab.org
  • GitLabGitLab
  • Issues
  • #219437
Closed
Open
Issue created May 28, 2020 by Arthur McGregor@arthurorbica

gitlab-ci: add support for job:when and rules:

Release notes

Previously it was impossible to configure a when: keyword for a CI job that had rules: this limits our users when defining their jobs in their CI/CD pipelines, in this release we've dropped that limitation by supporting job:when and rules: keyword allowing you to define jobs in your pipeline in a flexible way.

Summary

Documentation for Rules:If states:

If rules:when is not included in the configuration at all, the behavior defaults to job:when, which continues to default to on_success

To me, this suggests I can leave the when statement out of the if rules and specify the when statement at a job level. However, when I try this I get a YAML lint error.

My use case is that I am using the extends keyword to apply some custom rules to multiple jobs. However, only the deployment job should be manual (see sample .gitlab-ci.yml file below). I can get around this by making .custom-rule-manual and explicitly setting when: manual but then the if statement is duplicated, which I'd like to avoid.

Steps to reproduce

The following .gitlab-ci.yml file fails linting with the error jobs:deployjob config key may not be used with `rules`: when. I am using the GitLab.com CI Lint.

testJob:
  stage: test
  script:
    - echo Testing
  rules:
    - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $STAGE_BRANCH'
    
deployJob:
  stage: deploy
  when: manual
  script:
    - echo Deploying
  rules:
    - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $STAGE_BRANCH'

Proposal

  • The expected behavior is that we should add support for jobs:when and rules to support the above configuration
  • There was a discussion regarding the implicit and the explicit when (should one override the other?), however, eventually we agreed that implicit when should not override explicit when here and here.
  • Here is a short POC proposal
  • The change will not contain Breaking changes
Edited Dec 08, 2021 by Dov Hershkovitch
Assignee
Assign to
Time tracking