0

I am working to create webhook which any git push from Bitbucket will trigger Jenkin job to run on a Linux host (without plugin).

In jenkins, I created a simple pipeline, and came up with this webhook URL. http://admin:apiToken@www.myjenkins.com:8080/job/job123/build?token=xxxxxx I tested to run this webhook URL on CLI, it worked and I could see new job fired up successfully in Jenkins Portal.

$ curl -s --show-error http://admin:apiToken@www.myjenkins.com:8080/job/job123/build?token=xxxxxx

However, this URL is NOT working in Bitbucket's webhook setting (project > repo > repo settings > webhooks ) . I clicked 'test connection' it returned 403 with the following error response

Authentication required
<!--
You are authenticated as: anonymous
Groups that you are in:
  
Permission you need to have (but didn't): hudson.model.Hudson.Read
 ... which is implied by: hudson.security.Permission.GenericRead
 ... which is implied by: hudson.model.Hudson.Administer
-->

I used admin account but it said 'anonymous`.

I also tested git push and nothing happened in Jenkins. According to the error response, Looks like it related to authentication issue... but it was weird, command line with curl was working fine. That means:

  • authentication with admin token is fine.
  • resource URL is correct.

But the same doesn't work in Bitbucket.

Finally, I tested to enable anonymous account in Jenkins, the Bitbucket could trigger build to Jenkins but too risky. Does anyone have idea on my problem? Thanks

Bruce Lok
  • 21
  • 4

1 Answers1

1

Depending on what source control plugin you are using in Jenkins, there are several ways of achieving your goal:

  1. Bitbucket Server Integration plugin (https://plugins.jenkins.io/atlassian-bitbucket-server-integration/) After configuring it in the main Jenkins configuration page Jenkins main configuration page

(following the guides), you could select from Jenkins job - > Bitbucket server trigger build after push enter image description here

which will create a Webhook in Bitbucket repo automatically when applied/saved in Jenkins enter image description here

  1. Git plugin (https://plugins.jenkins.io/git/) In the Job configuration page, you could select "Build when a change is pushed to BitBucket"

enter image description here

which will work only after someone with admin rights to the repository creates the webhook manually with the following URL "{FULL_JENKINS_URL}/bitbucket-hook/"