'Make sure a job is rerun in later pipelines if it has failed in previous pipeline and is subject to files changes rules in Gitlab CI

I have a Gitlab CI job that has a rule making the job run if any of 3 paths are modified. I made the job fail purposefully. Then, I modified the README.md - a file that is not tracked by the job changes rule - and I pushed a new commit.

But the job was not retried. It therefore does not show the pipeline as failing, while the failing job has never been fixed (it just has not been rerun).

The job has not been rerun

What kind of rules can I set such that:

  • a job has a rules changes affected by some files AND
  • a job is retried at every pipeline in the branch/MR if it has not been resolved (regardless of changes status).

The pipeline:

image: python:3.6-alpine

workflow:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
      when: never
    - when: always

stages:
  - lint

flake8:
  image: python:3.6-alpine
  stage: lint
  before_script:
  - pip3 install flake8
  script:
    - echo "Running flake8.."
    - flake8 setup.py src
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      when: always
    - if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
      changes:
        - setup.py
        - src/**/*
        - .gitlab-ci.yml
  tags:
    - sometag

I have the following file architecture:

.
├── .gitlab-ci.yml
├── README.md
├── setup.py
└── src
    ├── foo.py
    └── __init__.py


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source