Bitbucket webhook to run jenkins job



I succesfuly sent a post request from curl to trigger jenkins job:

curl -I -X POST http://jenkinsAccountUserName:[email protected]:8080/job/projecty_ci/build -H "Jenkins-Crumb:a4fb99fbdb252fda3cc69ee575bedabc"

I don’t understand how to convert this to a url: Problem accessing /job/projecty_ci/build. Reason: No valid crumb was included in the request.

http://jenkinsAccountUserName:[email protected]:8080/job/projecty_ci/build?Jenkins-Crumb:a4fb99fbdb252fda3cc69ee575bedabc

this works fine from chrome but not from bitbucket webhooks.

What is the problem?

I created a job in jenkins which I can successfuly trigger by url.

When I’m triggering the same job from bitbucket’s webhook, I get the error: Problem accessing /job/projecty_ci/build. Reason: No valid crumb was included in the request.

enter image description here

enter image description here


Try to generate a CSRF token for use in your in your API requests.

  • GOTO: Jenkins > Manage Jenkins > Configure Global Security and enable
    Prevent Cross Site Request Forgery exploits.
  • Select Default Crumb Issuer from Crumb Algorithm and save to apply
    changes and enable.

Remote access API

You can get the crumb by calling the jenkins api and using it in your URL.

For curl/wget you can obtain the header needed in the request from the URL JENKINS_URL/crumbIssuer/api/xml (or …/api/json). Something like this:

wget -q --auth-no-challenge --user USERNAME --password PASSWORD --output-document - \

This will print something like “.crumb:1234abcd”, which you should add to the subsequent request.

Administer a Build

NOTE: To prevent CSRF, Jenkins require POST requests to include a crumb, which is specific to each user. The command to obtain the crumb is:

    CRUMB=$(curl --user $USER:$APITOKEN \

Start a build

$ curl -H ".crumb:<crumb_string>" -X POST http://<jenkins_url>/job/<job_name>/build --user <user_name>:<api_token>

Answered By – SoftwareCarpenter

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published