Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×With version 5.4 of the Bitbucket server, Atlasian (re-)introduced the webhooks. I tried to configure a webhook to notify our Jenkins 2.83 instance but the request was refused with an "Invalid crumb" message.
Please advise how to connect the new Bitbucket server webhooks to a Jenkins 2.x instance.
Please note that the invoked Jenkins job is of type Pipeline, which executes a parameterized script from an SCM.
Here are the details of the HTTP request and response:
Test connection event
https://jenkinshost/view/all/job/playground/job/test_pipeline/buildWithParameters
X-Request-Id: b346ae6c-f455-43f0-92c4-d5e74f922bfc X-Event-Key: diagnostics:ping
No headers
-------------------------------------------------------------------------
403
Cache-Control: must-revalidate,no-cache,no-store Server: Jetty(9.4.z-SNAPSHOT) X-Content-Type-Options: nosniff Content-Length: 460 Date: Wed, 11 Oct 2017 05:27:33 GMT Via: 1.1 localhost (Apache-HttpClient/4.4.1 (cache)) Content-Type: text/html; charset=ISO-8859-1
<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 /view/all/job/playground/job/test_pipeline/buildWithParameters. 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>
Our solution was to install "Pull request notifications" Bitbucket plugin:
It provides a good (for us) set of filters whether to trigger Jenkins for a build.
There is (at least) one main difference with the proposal of @Tomas Bjerre: "Pull request notifications" Bitbucket plugin filters (sends or not) the requests at the Bitbucket side, while the "Generic Webhook Trigger" Jenkins plugin decides only on Jenkins side if to fulfill a received build request.
The approach to select depends only on your needs and possibilities :-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This one allows you to insert the crumble and the documentation is a bit more accurate... But I am looking for a simple solution for:
1. Bitbucket: On pull request, calls Jenkins job with parameters and the two URLs: repository and forked repository,
2. Jenkins job merge and build and report result to the pull request on Bitbucket
3. Integrator can sip coffee instead of working hard... (:+)
But somehow, everything works apart of the "merge" between the two repository....
I am thirsty for advices
Thanks
Michele
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
stage('Checkout'){
// get the short commit hash to be used to tag our final image with it env.COMMIT_ID = env.PULL_REQUEST_FROM_HASH.substring(0,8)
echo 'WORKSPACE:' + env.WORKSPACE
echo 'COMMIT_ID:' + COMMIT_ID
echo 'PULL_REQUEST_ID:' + env.PULL_REQUEST_ID
echo 'PULL_REQUEST_VERSION:' + env.PULL_REQUEST_VERSION
echo 'PULL_REQUEST_AUTHOR_EMAIL:' + env.PULL_REQUEST_AUTHOR_EMAIL
echo 'PULL_REQUEST_USER_NAME:' + env.PULL_REQUEST_USER_NAME
echo 'PULL_REQUEST_AUTHOR_NAME:' + env.PULL_REQUEST_AUTHOR_NAME
echo 'PULL_REQUEST_TO_BRANCH:' + env.PULL_REQUEST_TO_BRANCH
echo 'PULL_REQUEST_FROM_HASH:' + env.PULL_REQUEST_FROM_HASH
echo 'PULL_REQUEST_FROM_BRANCH:' + env.PULL_REQUEST_FROM_BRANCH
echo 'PULL_REQUEST_FROM_ID:' + env.PULL_REQUEST_FROM_ID
echo 'PULL_REQUEST_AUTHOR_DISPLAY_NAME:' + env.PULL_REQUEST_AUTHOR_DISPLAY_NAME
echo 'PULL_REQUEST_TITLE:' + env.PULL_REQUEST_TITLE
// checkout from bitbucket
env.COMMIT_HASH = env.PULL_REQUEST_FROM_HASH
echo '(Jenkinsfile) checking out from: ' + env.PULL_REQUEST_FROM_ID
checkout([$class: 'GitSCM', branches: [[name: "${env.PULL_REQUEST_FROM_ID}"]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'e4054b90-d76b-4ae2-bc10-REDACTED', url: 'ssh://git@REDACTED.git']]])
sh "git config --global user.email '${env.PULL_REQUEST_AUTHOR_EMAIL}'"
sh "git config --global user.name '${env.PULL_REQUEST_USER_NAME}'"
sh "git merge origin/${env.PULL_REQUEST_TO_BRANCH}"
// notify bitbucket that the job is in progress notifyBitbucket('INPROGRESS') }
We use the pull request notifier plugin to do what you are describing. Here is an example. Note how we merge in the PULL_REQUEST_TO_BRANCH
sh "git merge origin/${env.PULL_REQUEST_TO_BRANCH}"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.