5

Background

My git repository is hosted by a Gerrit server. We also use Jenkins, along with the Gerrit Event and Git Plugin, to trigger automatic jenkins jobs build when a review is pushed to Gerrit.

Say the git repo has the following folder structure

ProjectA
    - .git
    - folderA
    - folderA/folderA1
    - folderA/manual_tests
    - folderA/manual_tests/file1
    - folderB
    - folderB/folderB1
    - folderB/manual_tests/file2
    - folderC
    - folderC/folderC1
    - folderC/manual_tests/file3
    - folderD
    - folderD/folderD1
    - folderD/folderD1/FolderD11
    - folderD/folderD1/FolderD11/manual_tests/file4
    - folderD/folderD1/FolderD12
    - folderD/folderD2

Currently, the Jenkins job is defined to run on all branches by specifying Type Path with pattern **. This config causes the job to run with every review.

The Issue

Here's what I'm trying to accomplish:

  • If the code review only contains changes made to any manual_tests folder, I don't want to Jenkins Jobs to get triggered.
  • If the review contains at least least one file/folder that is not manual_tests, the trigger the jobs

I tried adding a File Path with type RegExp with a pattern of (?!.*manual_tests.*).*, but this did not achieve my end goals. I tried various regular expression patterns, but I never got the end goal.

Is it possible to not trigger a Jenkins job if a gerrit review only contains changes in manual_tests folders?

bkhouri
  • 243
  • 5
  • 13

2 Answers2

2

The trick to getting this working is that the COMMIT_MSG file must be omitted in the regex as well.

This bug report describes the problem and workaround: https://issues.jenkins-ci.org/browse/JENKINS-19891

The fix is simply to use the following RegExp pattern:

^((?!manual_tests|\/COMMIT_MSG).)*$
actf
  • 509
  • 4
  • 12
1

The Add Topic button below the form reveals such a functionality.

screen shot from Gerrit

The help text explains:

Then you can optionally provide the name of the specific file path(s) and topic names to trigger on.

  • To only trigger builds if the patch set contains files in a certain folder.
  • To only trigger builds if the change belongs to a topic.
StephenKing
  • 30,871
  • 9
  • 73
  • 105