简体   繁体   English

检查Jenkins版本中回购的一部分是否未更改

[英]Check if a part of a repo has not changed on a Jenkins build

On a Jenkins build I'd like to skip some tests if a part of the repository hasn't changed. 在Jenkins构建中,如果存储库的一部分未更改,我想跳过一些测试。 This could save a lot of time on the build process. 这样可以节省大量的构建时间。 Here's how I can do it on my dev machine: 这是我可以在开发机上完成的方法:

changes=$(git log --name-only --pretty="" my_branch..HEAD | grep path/to/folder)
if [[ -z $changes ]]; then
  echo "no changes detected, skipping tests"
  exit 0
fi
echo "running tests!"

How do I do this on a Jenkins machine? 如何在Jenkins机器上执行此操作?

I'm using a git plugin for Jenkins and it can figure my branch name with $GIT_BRANCH , but I'm clueless how to get a list of file changes on my build. 我正在为Jenkins使用git插件 ,它可以使用$GIT_BRANCH来确定我的分支名称,但是我不知道如何在构建中获取文件更改列表。

In a Freestyle job, you will probably have to use the conditional build step plugin. 在Freestyle作业中,您可能必须使用条件构建步骤插件。 I don't think you can run a shell script as one of the conditions, but you can run one step to execute your shell script you pasted, and have it touch a file if you should (or should not) run a test. 我不认为您可以运行shell脚本作为条件之一,但是可以运行一个步骤来执行粘贴的shell脚本,如果您应该(或不应该)运行测试,则可以使其碰到文件。 Then use the Conditional Build Step to look for that file and do the right thing. 然后使用“条件构建”步骤查找该文件并执行正确的操作。

I also just realized that one of the Additional Behaviors that the git plugin has is Polling ignores commits in certain paths . 我还刚刚意识到git插件具有的其他行为之一是轮询会忽略某些路径中的提交 This allows you to specify includes or excludes. 这使您可以指定包含或排除。 If you specify the "Includes" the job won't even trigger a build at all if files other than those are modified. 如果您指定“包含”,则修改以外的文件甚至根本不会触发构建。 Then you don't even need your shell script or to take up an executor to check the changes. 然后,您甚至不需要外壳程序脚本或使用执行程序来检查更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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