简体   繁体   中英

How to trigger a jenkins job if there is any GIT changes only on specific set of folder structure not entire repo

I just have a folder structure as below:

src (parent)

    test/resources

    main/resources

    test/java

    main/java

I just want to trigger the Jenkins job if there is any change only in main/resources or test/resources folders from git repository.

Actually those resources having only test data sheets like xlsx and test suites which is in xml format. So I just want to trigger a job if there is any newly added data sheet or updates in the existing data sheet.

I didn't want working code for this. Just need some idea how or wanna know plugins that will do this job.

You can trigger the jenkins job after each commit.

There are scripts called git hooks that are executed when you take various actions using git.

In this case you can use post-commit hook. Whatever script you put at <your-project-location>/.git/hooks/post-commit will be executed.

Assuming you can trigger the jenkins job using a script called "trigger-jenkins.sh", put the below script into post-commit file located in <your-project-location>/.git/hooks/post-commit

#!/bin/bash
if git show | grep -E 'a/main/resources|a/test/resources'; then
        ./trigger-jenkins.sh
fi

make sure you make the post-commit file executable

chmod +x <your-project-location>/.git/hooks/post-commit

now everytime you make a change to test/resources and main/resources and commit it, git will execute trigger-jenkins.sh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM