There is a way to skip "test stage" if only the specific folder is modified?

Hi!

I have a full pipeline, but I want to improve it avoiding that if the content of the “helm” folder is modified , I don’t want run the test stage.

I have seen the only method, but I don’t know how to implement it for this specific scenario

This is possible?

Thank you very much

If you are looking to skip the job any time the helm directory is modified, it is quite straightforward using the rules clause:

rules:
- changes:
    - helm/*
  when: never

Unfortunately, I think you cannot at the moment skip a job if only files inside the helm directory have changed. The rule before matches any time the helm directory have some changes.

What you can do is putting something in the commit message, and use the rules:if clause to skip the job if the commit message matches something.

1 Like

But messages commits could be entered manually, I would like avoid human errors.

There are a way to examine all files modified and skip the stage even with exit if there is no other way, reading changes in git or something?

If changes all line contain the folder then skip or exit this stage, otherwise do it.

What do you think?

Thank you

I can’t use rules with only?¿

I have that only execute tests when branch start with that, but I want also that if helm-charts is modified don’t execute it…

jobs:test_maven_stage config key may not be used with `rules`: only

  only:
    - /^feature\/.*$/
    - /^hotfix\/.*$/
  rules:
    - changes:
        - helm-charts
      when: never

You can do that, but if there are changes to both helm-charts and to other files, the job will be skipped. Anytime the helm-charts directory is modified, the job skips, no matter the state of other files.

I’ve tried this

  rules:
    - if: '$CI_COMMIT_BRANCH == "/^feature\/.*$/"'
      when: always
    - if: '$CI_COMMIT_BRANCH == "/^hotfix\/.*$/"'
      when: always
    - changes:
        - helm-charts
      when: never

But I think the regex is not working like when I had “only” condition. Because I have a branch feature, I modified readme and the pipeline omit the stage :S

What do you think is the better way to accomplish it?

Thank you!

I was trying detect changes in that folder using git in pipeline like that but I don’t know why I’m receiving that error, locally the command works

git diff --name-only origin/master $CI_COMMIT_BRANCH | grep helm-chart

$ echo $CI_COMMIT_BRANCH
feature/test-david
$ git diff --name-only origin/master $CI_COMMIT_BRANCH | grep helm-chart
fatal: ambiguous argument 'origin/master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
ERROR: Job failed: exit code 1

Any help?

Thank you very much

Any suggetion, I’m trying debug but I don’t have lucky

I can’t do that command that locally works, but inside pipeline doesn’t work

git diff --name-only origin/master $CI_COMMIT_BRANCH | grep helm-chart

This is the debug log into pipeline

$ echo $CI_COMMIT_BRANCH
feature/test-david
$ git remote -v
origin  https://gitlab-ci-token:[MASKED]@gitlab.com/xxxx/it-applications/xxxx-apps/ab-backend.git (fetch)
origin  https://gitlab-ci-token:[MASKED]@gitlab.com/xxxx/it-applications/xxxx-apps/ab-backend.git (push)
$ git checkout $CI_COMMIT_BRANCH
Switched to branch 'feature/test-david'
Your branch is up-to-date with 'origin/feature/test-david'.
$ git remote -v
origin  https://gitlab-ci-token:[MASKED]@gitlab.com/xxx/it-applications/xxxx-apps/ab-backend.git (fetch)
origin  https://gitlab-ci-token:[MASKED]@gitlab.com/xxx/it-applications/xxxx-apps/ab-backend.git (push)
$ git branch -a
* feature/test-david
  remotes/origin/feature/test-david
$ git diff --name-only master
fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
ERROR: Job failed: exit code 1

Please, any idea?

I’m sorry, I really don’t know how to achieve what you want.

However, the problem you are facing now with git diff should be easy to solve: you add git pull before the diff :slight_smile:

I tried with git pull but I have the same error

I’m doing something wrong in my git diff?

$ git pull
From https://gitlab.com/xxx/it-applications/ab-apps/xxx-backend
 * [new branch]      BLB-TTB               -> origin/BLB-TTB
 * [new branch]      feature/add-id-to-bluserdto-for-external-integration-trial -> origin/feature/add-id-to-bluserdto-for-external-integration-trial
 * [new branch]      feature/change-app-token -> origin/feature/change-app-token
 * [new branch]      hotfix/revert-ops-345 -> origin/hotfix/revert-ops-345
 * [new branch]      master                -> origin/master
Already up-to-date.
$ git diff --name-only master
fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
ERROR: Job failed: exit code 1

Thank you very much