[英]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.如果仅在 git 存储库中的 main/resources 或 test/resources 文件夹中有任何更改,我只想触发 Jenkins 作业。
Actually those resources having only test data sheets like xlsx and test suites which is in xml format.实际上,那些资源只有测试数据表,如 xlsx 和 xml 格式的测试套件。 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.您可以在每次提交后触发 jenkins 作业。
There are scripts called git hooks that are executed when you take various actions using git.当您使用 git 执行各种操作时,会执行称为 git hooks 的脚本。
In this case you can use post-commit hook.在这种情况下,您可以使用提交后挂钩。 Whatever script you put at <your-project-location>/.git/hooks/post-commit
will be executed.你放在<your-project-location>/.git/hooks/post-commit
任何脚本都会被执行。
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
假设您可以使用名为“trigger-jenkins.sh”的脚本触发 jenkins 作业,请将以下脚本放入位于<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现在每次你对 test/resources 和 main/resources 进行更改并提交时,git 将执行 trigger-jenkins.sh
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.