简体   繁体   中英

Bitbucket and Jenkins remote build trigger

What I am trying to achieve

Trigger a build from Bitbucket when a pull request is created using the remote trigger option in Jenkins. So I created a job in Jenkins and configured to trigger a build with the remote API.

在此输入图像描述

In Bitbucket I created a webhook to trigger the build with the following URL structure:

http://jenkins_server_ip:port/job/job-name/build?token=<t1>

I get the following error:

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
        <title>Error 403 No valid crumb was included in the request</title>
    </head>
    <body>
        <h2>HTTP ERROR 403</h2>
        <p>Problem accessing /job/android-sample/build. Reason:

            <pre>    No valid crumb was included in the request</pre>
        </p>
        <hr>
        <a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.z-SNAPSHOT</a>
        <hr/>
    </body>
</html>

I digged into the internet and some says that we need to use the crumbIssuer API in Jenkins which is done with wget . How can I use this in Bitbucket?

您可以关闭CSRF安全检查:system configure→ 配置全局安全性CSRF保护 ,取消选中该复选框。

You have to get the crumb key from Jenkins first and insert it into your build request's HTTP header. The crumb is for protecting from CSRF attacks.

The following Bash commands uses curl to send the build request, and it works well:

CRUMB=`curl -u $USER:$PASS 'http://$SERVER:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)'`
curl -H $CRUMB -u $USER:PASS 'http://$SERVER:8080/job/$PROJECT/build?token=$UR_TOKEN'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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