POST hook on Bitbucket

后端 未结 2 1711
刺人心
刺人心 2020-12-17 16:47

How to use the POST url in bitbucket on private Jenkins?

I have been experiencing problems with bitbucket and their post commit.

Description :

2条回答
  •  情歌与酒
    2020-12-17 17:27

    If you want to make BitBucket trigger a Jenkins job execution after a commit in your repo, you have two options:

    • Use the POST hook
    • Use the Jenkins hook

    Both using the Jenkins API to trigger the job.

    For the POST hook, you basically need to build the url as this:

    https://USER:APITOKEN@JENKINS_URL/job/JOBNAME/build?token=TOKEN
    

    where:

    • USER: is the Jenkins user that will trigger the job
    • APITOKEN: is a token associated to that user to allow the use of the API, you can get it from the user configuration page in Jenkins
    • JENKINS_URL: the url of your jenkins server
    • JOBNAME: the name of the job
    • TOKEN: the token associated to the job, you must add it in the job configuration page (enable remote triggers)

    The cool thing about this is that you can check if it works just using curl from the console.

    Also note there is no password in the url, you have the API TOKEN instead, this is to avoid publishing your user and password. Something else you can do to improve security a little bit, if you have admin rights in the Jenkins server, create a new user with just access rights to read and build jobs, and use it only for this. So you don't have to publish your own user and token, which may have admin rights.

    The Jenkins hook works the same way, building the same URL for you, but you don't have the chance to test it (for instance, using curl).

    This is based on these documents:

    • Jenkins Remote Access API (submitting jobs)
    • Jenkins hook management (check out the comments)
    • Hooking BitBucket up with Jenkins (this is VERY useful if you want to try the Jenkins hook)

    Hope it helps.

    Ger

提交回复
热议问题