3

Issue I am facing is the following:

  • I want to trigger a job which is setup on Jenkins from BitBucket (on push)
  • I want to tigger it and to pass parameters
  • Trigger job without params is working, but as soon as I add params, nothing is triggered and I don't get any logs.

Here is my url on Jenkins (which is working)

http://someJenkinsInstance/bitbucket-hook/

And here is url that I would like to use (at least use params)

http://someJenkinsInstance/bitbucket-hook/buildWithParameters?BRANCH=master&ENVIRONMENT=dev

On Jenkins side, I'm using the plugin "Bitbucket hook" and in BitBucket plugin is "Post web hooks".

Note: I am using Bitbucket server not cloud version.

G. Frx
  • 2,350
  • 3
  • 19
  • 31
  • You are probably looking for the [Remote Access API](https://wiki.jenkins.io/display/JENKINS/Remote+access+API). – LightBender Apr 04 '18 at 14:04
  • check this https://stackoverflow.com/questions/20359810/how-to-trigger-jenkins-builds-remotely-and-to-pass-parameters – Yuri G. Apr 04 '18 at 16:51
  • 1
    @YuriG. Well I checked this solution but problem is with latest version of Jenkins, we can't call Job by url using GET. It must be using POST. So my build is not triggered. – G. Frx Apr 05 '18 at 06:16
  • the fastest way will be to create your own hook script that will make a POST request and to put it in the repo – Yuri G. Apr 05 '18 at 18:19

1 Answers1

0

It is easy to add parameter in web hook. Here I am considering a generic web hook

https://[COMPANY_NAME].com/generic-webhook-trigger/invoke?token=[TOKEN_NAME]&name=testing&type=pool_request

To get the result of name and type you need to setup pipeline job and select generic web hook trigger then select request parameter and enter name and another one is type Screenshot enter image description here

Now all you need to create a bash script or Jenkins/groovy so lets consider Jenkins groovy file and paste the below and try to trigger you web hook.

node()
{
    print "name = ${name}"
    print "Type ${type}"
}

Similar you can create a parameterised web hook for parameterized job

JENKINS_URL/job/ParameterizedJobName/buildWithParameters?token=TOKEN_NAME&name=testing&type=testing

And following parameters to your job enter image description here

Then select Execute shell and write following code

echo $name $type

An example with generic web hook job (not parameterized job):- https://www.svastikkka.com/2021/01/how-to-pass-parameter-in-webhook.html

Manshu Sharma
  • 83
  • 1
  • 8