git 根据存储拉取请求触发 jenkins 构建

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29937828/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:57:09  来源:igfitidea点击:

Trigger jenkins build on stash pull request

gitjenkinsconfigurationpull-requestbitbucket-server

提问by Adr3nl

I've been trying to get the build on PR working for some time now following the usual guides. However i ran into some issues.

一段时间以来,我一直在尝试按照通常的指南构建 PR。但是我遇到了一些问题。

Here is what i added to the previously existing configuration @ Jenkins project:

这是我在先前存在的配置@Jenkins 项目中添加的内容:

Source Code Management:
Multiple SCMs
 - Repository URL: ssh://[email protected]/projectCode/RepName.git
 - Credentials with ssh key working
 - Batches to build: */${sourceBranch}
 - Repository browser: auto
 - Additional Behaviours: none

Build triggers:
 - Poll SCM

And the the previous working build & post-build actions

以及之前的工作构建和构建后操作

On the stash side there is not much to configure. Here is a ss of the existing configurations and its test result @ Settings -> Hooks -> Stash WebHook to Jenkins:

在存储方面没有太多配置。这是现有配置的 ss 及其测试结果@Settings -> Hooks -> Stash WebHook to Jenkins:

Stash webhook config

存储网络钩子配置

As you can see in the screenshot, the test for this configuration works and it is able to properly send a message to Jenkins. It is received by Jenkins with the following log message:

正如您在屏幕截图中看到的,此配置的测试有效,并且能够正确地向 Jenkins 发送消息。Jenkins 收到它并带有以下日志消息:

Started on Apr 29, 2015 8:01:23 AM
Polling SCM changes on master
Using strategy: Default
using GIT_SSH to set credentials 
 > git --version # timeout=10
 > git -c core.askpass=true ls-remote -h ssh://[email protected]/glp/golivephone.git # timeout=10
Done. Took 0.18 sec
No changes

Right, i didn't change anything! The problem is when i go to an actual branch and click "Trigger build". The Git polling Log stays exactly the same and no messages is sent to Jenkins. Am i missing some configuration step @ stash or in the branch creation? I dont think it is related to the jenkins build, since i dont even get a Pooling log message when i trigger the build. Even a debug idea would be nice to find out what's wrong.

对,我什么都没变!问题是当我转到实际分支并单击“触发构建”时。Git 轮询日志保持完全相同,没有消息发送到 Jenkins。我是否缺少@ stash 或分支创建中的一些配置步骤?我不认为它与 jenkins 构建有关,因为当我触发构建时我什至没有收到池化日志消息。即使是调试想法也能很好地找出问题所在。

Edit:

编辑:

Network activity when i trigger a build is triggered: Request

触发构建时的网络活动被触发:请求

Remote Address:10.211.8.19:443
URL:https://stash.fraunhofer.pt/rest/jenkins/latest/projects/projectCode/repos/repName/triggerJenkins?branch=bugfix/GLP-702-about-screen-doesn-t-update-on-subscription&sha1=cd49ac1be47e89ecc4f02c1d3867d54e2b2ff78a
Request Method:POST
Status Code:204 No Content

---PAYLOAD---
none

---Query String parameter---
branch:bugfix/GLP-702-about-screen-doesn-t-update-on-subscription
sha1:cd49ac1be47e89ecc4f02c1d3867d54e2b2ff78a

compared to the test one:

与测试一相比:

Remote Address:10.211.8.19:443
Request URL:https://stash.fraunhofer.pt/rest/jenkins/latest/projects/projectCode/repos/repName/test
Request Method:POST
Status Code:200 OK

---PAYLOAD---
{jenkinsBase: ["http://i-255.cloud.fraunhofer.pt:8080/"],…}
gitRepoUrl: ["ssh://[email protected]/glp/golivephone.git"]
0: "ssh://[email protected]/glp/golivephone.git"
ignoreCerts: ["TRUE"]
0: "TRUE"
jenkinsBase: ["http://i-255.cloud.fraunhofer.pt:8080/"]
0: "http://i-255.cloud.fraunhofer.pt:8080/"
omitHashCode: ["TRUE"]
0: "TRUE"

---Query String parameter---
none

回答by Christian Galsterer

You may have a look at https://christiangalsterer.wordpress.com/2015/04/23/continuous-integration-for-pull-requests-with-jenkins-and-stash/where I describe the detailed steps how to setup Jenkins and Stash to trigger automatically the correct Jenkins build(s) when a pull request is created or updated.

您可以查看https://christiangalsterer.wordpress.com/2015/04/23/continuous-integration-for-pull-requests-with-jenkins-and-stash/在那里我描述了如何设置 Jenkins 的详细步骤和 Stash 在创建或更新拉取请求时自动触发正确的 Jenkins 构建。

It uses the Jenkins Git Plugin and the Pull Request Notifier for Stash add-onand selects the correct build using the notification feature of the Jenkins Git Plugin.

它使用 Jenkins Git 插件和用于 Stash 附加组件拉取请求通知程序,并使用 Jenkins Git 插件的通知功能选择正确的构建。