轮询特定分支 Jenkins 的 SCM

JPH*_*ett 5 git jenkins

我有一个有很多分支的 Github 项目。

Example

master
staging
feature-1
feature-2
Run Code Online (Sandbox Code Playgroud)

我有一个 Jenkins 作业,它启用了以下 cronjob 的“Poll SCM”选项(10 7,9,11,13,15,17,19 * * 1-5)

但是,当对 master 进行更改时,这项工作也将开始。

我希望 Jenkins 的工作只有在提交到暂存分支时才开始。

这是轮询日志的输出

Started on Nov 20, 2018 1:10:00 PM
no polling baseline in /var/jenkins_workspace/workspace/Staging-ALL-Deploy@libs/jenkins-pipeline-global-lib on 
Using strategy: Default
[poll] Last Built Revision: Revision efccc8e212470802d64537e0a5e710f9b5c063b6 (refs/remotes/origin/staging)
 > git --version # timeout=10
 > git ls-remote -h http://git.company.com/org/repo.git # timeout=10
Found 56 remote heads on http://git.company.com/org/repo.git
[poll] Latest remote head revision on refs/heads/staging is: efccc8e212470802d64537e0a5e710f9b5c063b6 - already built by 171
Using strategy: Default
[poll] Last Built Revision: Revision efccc8e212470802d64537e0a5e710f9b5c063b6 (refs/remotes/origin/staging)
 > git --version # timeout=10
 > git ls-remote -h http://git.company.com/org/repo.git # timeout=10
Found 56 remote heads on http://git.company.com/org/repo.git
[poll] Latest remote head revision on refs/heads/master is: 865459e59ef5f91fddbd7453d9f2205560327c44
Done. Took 0.46 sec
Changes found
Run Code Online (Sandbox Code Playgroud)

这可能吗?

谢谢约翰

小智 2

您可以通过以下方式设置要构建的分支:

配置 -> 源代码管理选项卡 -> 分支构建 -> 分支说明符

只需在本节中写出暂存即可。然后转到“构建触发器”选项卡,选择 GitHub hook 触发器进行 GITScm 轮询。

不要忘记将 webhook 添加<YOUR-JENKINS-URL>/github-webhook/到您的 Github 项目并选择以 json 形式发送推送事件。

通过这种方式,只要推送到特定分支,您就可以创建一个构建。通过池化,它将以给定的时间间隔拉取存储库,这成本更高。