-->

Trigger jenkins build on stash pull request

2019-08-10 17:45发布

问题:

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.

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

Source Code Management:
Multiple SCMs
 - Repository URL: ssh://git@git.company.pt/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:

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:

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://git@git.fraunhofer.pt/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.

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://git@git.fraunhofer.pt/glp/golivephone.git"]
0: "ssh://git@git.fraunhofer.pt/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

回答1:

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.

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