0

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 Answers2

0

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.

ycr
  • 12,828
  • 2
  • 25
  • 45
  • I am looking to trigger pipeline only the specific file is triggered as the gets updated very rarely like once every 3 months or so.. I don't want to run the pipeline for every check-ins. – nagarjuna v Jun 20 '23 at 17:10
0

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