简体   繁体   English

Jenkins:从 GitHub 网络钩子触发构建的作业仅在主节点上运行

[英]Jenkins: Jobs triggered to build from GitHub web-hook run only on master node

The initial idea was to trigger a specific build on a specific node (slave), after merging changes to master branch on GitHub.最初的想法是在将更改合并到 GitHub 上的 master 分支后,在特定节点(从属节点)上触发特定构建。

Configuration:配置:

  1. Jenkins (ver 2.226) is on a Centos8 VM machine in VirtualBox; Jenkins (ver 2.226) 在 VirtualBox 中的 Centos8 VM 机器上;
  2. VM setup: Java 11 OpenJDK(openjdk version "11.0.5"), git version 2.18.2 VM 设置:Java 11 OpenJDK(openjdk 版本“11.0.5”),git 版本 2.18.2

Steps done:完成的步骤:

  1. Created a Jenkins project (job) that clones a Github repo and runs some mvn commands on it;创建了一个 Jenkins 项目(作业),它克隆了一个 Github 存储库并在其上运行了一些 mvn 命令;
  2. Configured the job to run on a new node, except from the master node;将作业配置为在新节点上运行,主节点除外;

As expected: The job runns properly.正如预期的那样:作业运行正常。

  1. I used ngrok to expose my Jenkins server and generate an external link to it;我使用 ngrok 来公开我的 Jenkins 服务器并生成一个外部链接;
  2. Added the ' http://bla.ngrok.io/github-webhook/ ' payload url to GitHub;向 GitHub 添加了“ http://bla.ngrok.io/github-webhook/”payload url;

As expected: I can ping the Jenkins server successfully.正如预期的那样:我可以成功 ping Jenkins 服务器。

  1. In Jenkins I configured the job to be triggered trought SCM (enabled 'GitHub hook trigger for GITScm polling');在 Jenkins 中,我将作业配置为通过 SCM 触发(启用“GitHub hook trigger for GITScm polling”);
  2. Then I go to GitHub and commit a change to the master branch.然后我去 GitHub 并提交对 master 分支的更改。

Actual results: The build is triggered but only on the Master node.实际结果:构建被触发,但仅在主节点上触发。

  1. I marked as offline the Master node as to force the triggered job to be executed on the new slave.我将主节点标记为离线,以强制在新从节点上执行触发的作业。 Actual results: Nothing happens.实际结果:没有任何反应。

  2. I enabled the Master node and tried to trigger the job again.我启用了主节点并尝试再次触发作业。 Actual results: Nothing happens.实际结果:没有任何反应。

I have tail-ed the jenkins.log file to see what happens, and the 'poked build' action is recorded.我跟踪 jenkins.log 文件以查看发生了什么,并记录了“戳构建”操作。 After this, probably it waits to execute the build but this never happens.在此之后,它可能会等待执行构建,但这从未发生过。 At the end the 'Periodic background build discarder' is started.最后,“定期后台构建丢弃程序”启动。

2020-03-24 21:35:11.733+0000 [id=16]    INFO    o.j.p.g.w.s.DefaultPushGHEventSubscriber#onEvent: Received PushEvent for https://github.com/some/some_project from [someip] ⇒ http://blah.ngrok.io:8080/github-webhook/
2020-03-24 21:35:11.734+0000 [id=16]    INFO    o.j.p.g.w.s.DefaultPushGHEventSubscriber$1#run: Poked simple_build
2020-03-24 21:39:07.386+0000 [id=206]   INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Started Periodic background build discarder
2020-03-24 21:39:07.403+0000 [id=206]   INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Finished Periodic back

Am I missing something?我错过了什么吗?

Is the web-hook trigger build action restricted to execute only on the Master node? web-hook 触发器构建操作是否仅限于在主节点上执行?

I have managed to find a solution to the problem.我设法找到了解决问题的方法。 Now builds are triggered and run on the node that was set in the build configuration screen.现在构建被触发并在构建配置屏幕中设置的节点上运行。

What I have done is to set the master node to be used only when it is needed.我所做的是将主节点设置为仅在需要时使用。

To do this you need to:为此,您需要:

  • Go to 'Manage Jenkins > Configure System' and on the 'Usage' field selected the 'Only build jobs with label expression matching this node'转到“管理 Jenkins > 配置系统”并在“使用”字段中选择“仅使用与此节点匹配的标签表达式构建作业”
  • Save the settings.保存设置。

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

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