Trigger build when the content of specific file merged in gerrit repo

103 Views Asked by At

I am looking to create a Jenkins pipeline job that triggers when the content of the file filename.json changes merged in the Gerrit repository's master branch.

.
├── Readme
├── tools-
└── src
    └── main
        ├── com
        │   └── xx
        ├── A
        │   ├── B
        │   ├── C
        │   ├── xx.conf
        │   ├── yy.conf
        │   ├── filename.json
        │   ├── cc
        │   └── dd.conf
        ├── dddd
        │   └── dd.yml
        └── gee

Can someone help with right Jenkins pipeline configuration instructions to trigger and perform necessary CI steps for that specific file trigger.

Environment: src code in gerrit 3.7 Jenkins version: 2.38

Thanks in advance.

I tried to use Gerrit trigger event in Jenkins configuration.. looks like missing the correct Dynamic trigger settings and check merged settings.

I'm looking for correct instructions for the Gerrit trigger plugin in Jenkins . {coudn't'add the snap-shot here}

Dynamic Trigger Configuration:  http://gerrit-{domain}.com
Gerrit Project: 
    Plain: {repo=name}
    Plain: refs/head/master
    Path: ops/vuln-feed/{filename}.json

gerrit url:http://gerrit-{domain}.com
repo name:  {repo-name}
filename: ops/vuln-feed/{filename}.json

This one does not trigger the Jenkins job upon merging changes in file: ops/vuln-feed/filename.json into master branch.

2

There are 2 best solutions below

1
ycr On

You can probably use Jenkins when {} directive as explained here with a file pattern.

when { changeset pattern: "*/*filename.json", caseSensitive: true }

The issue with this approach is the Pipeline will execute and the stages will be skipped if the filename doesn't match.

0
Ashish Kumar On

You can do with the includeRegion and ExcludeRegion

checkout scmGit(
       branches: [[name: '*/master']],
       extensions: [[$class: 'PathRestriction', 
       excludedRegions: '''
           myapp/src/main/web/.*\\.html
           myapp/src/main/web/.*\\.jpeg
           myapp/src/main/web/.*\\.gif
       ''', 
       includedRegions: '  myapp/var/*'], 
       cleanBeforeCheckout()], 
       userRemoteConfigs: [[credentialsId: GitHTTPSCredentials,url:ManifestRepoUrl]])

Check this for reference https://github.com/jenkinsci/git-plugin#polling-ignores-commits-in-certain-paths