12

I need to skip a GitLab CI job in my pipeline, if the only changes part of my commit/merge request are related to *.md, eslintrc.json or jsconfig.json files.

Examples:

  • If these files have changed, but others like *.js have changed too: job should run.
  • If these files are not changed at all, but other *.js files have changed: job should run.
  • If README.md and eslintrc.json have changed and nothing else has changed: job should not run.

I have tried to accomplish this, but I have not found except:changes nor rules:when:never useful so far. How can I do it?

2 Answers2

2

If I get you correctly, you need to have except:changes convention in your CI file.

Take a look at this example. The Job runs in any condition in case the *.md, eslintrc.json, and jsconfig.json have changed. In that case, the pipeline won't run. Check the except-changes stage of the below example.

On the other hand, you can set to run the pipeline in case any js files have changed. Check the * only-changes* stage of the below example.

stages:
  - except-changes
  - only-changes

ignore-file-changes:
  stage: except-changes
  script:
    - echo "Skip running the pipeline if *.md, eslintrc.json and jsconfig.json has any kind of change."
  except: 
    changes:
      - "**/*.md"
      - eslintrc.json
      - jsconfig.json
      - README.md
  
pass-the-pipeline:
  stage: only-changes
  script:
    - echo "Run only *.js and Dockerfile files has any kind of change."
  only:
    changes:
      - Dockerfile
      - "**/*.js"

Numb95
  • 103
  • 2
  • 2
    In your example, if README.md changed and a *.js file changed as well, the job would not run. because of the except clause. I am asking how I could make it run if that is the case. – Gabriel Serrano Salas Dec 07 '21 at 22:38
  • I just think about that and actually, it comes into my mind that in case we just run the pipeline on *.js files the problem is solved. `README.md` file and *.js file changes, the pipeline runs. If any other files except the files which we set in the pipeline has been changed, the pipeline won't run. – Numb95 Dec 07 '21 at 22:47
  • 3
    *.js file are just as an example. The job should run for all other files in the repository except for those 3 I mentioned. And they are hundreds so I can not list them all. Hence, my question. – Gabriel Serrano Salas Dec 07 '21 at 23:08
2

There is a similar question with this problem including a suggestion for a workaround in the comments. (Is there a way to skip a pipeline when there are markdown changes only?) The rules:when:never or except:changes feature doesn't seem to support this at the moment. They opened a ticket with GitLab.

svov
  • 21
  • 4