Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

How to trigger Jenkins 2.1 with parameters #132

Closed
shlomipm opened this issue Jul 15, 2016 · 18 comments
Closed

How to trigger Jenkins 2.1 with parameters #132

shlomipm opened this issue Jul 15, 2016 · 18 comments
Labels

Comments

@shlomipm
Copy link

shlomipm commented Jul 15, 2016

Hi, I Just download this plugin with Bitbucket 4.7.1 When trying to trasfer parameters to jenkins (2.1) i'm getting nothing. e.g. "The URL to invoke when notification is triggered" - https:///job/eventhubutils_Build_mvn/buildWithParameters?FROM_REPO=${PULL_REQUEST_FROM_REPO_NAME}&TO_REPO=${PULL_REQUEST_TO_REPO_NAME}&PULL_REQUEST_USER_DISPLAY_NAME=${PULL_REQUEST_USER_DISPLAY_NAME}&EVERYTHING_URL=${EVERYTHING_URL} Can you advise?

PS - the 'Build with Parameters' started but all the parameters are blank.
(Bitbucket server is Windows and Jenkins is Linux)

@tomasbjerre
Copy link
Owner

What do you get when you this?

curl -u username:password 'http://localhost:7990/bitbucket/rest/prnfb-admin/1.0/settings/notifications' -H 'Accept: application/json, text/javascript, */*; q=0.01'

I would suspect its a Jenkins thing. The values are probably supplied by this plugin but not consumed by Jenkins. You may confirm that by changing the URL to, perhaps, an Apache installation and then check the logs of that to see what URL was actually invoked.

If you dont have such installation, you can change URL to:
http://cogi.bjurr.se/?FROM_REPO=${PULL_REQUEST_FROM_REPO_NAME}&TO_REPO=${PULL_REQUEST_TO_REPO_NAME}&PULL_REQUEST_USER_DISPLAY_NAME=${PULL_REQUEST_USER_DISPLAY_NAME}&EVERYTHING_URL=${EVERYTHING_URL}
And I will check my logs.

Also is there any stacktrace in the logs of Bitbucket Server?

@shlomipm
Copy link
Author

shlomipm commented Jul 16, 2016

I've changed it to your URL and i'm triggering it now.
Please update what do you get.

Thanks for your help.

@tomasbjerre
Copy link
Owner

tomasbjerre commented Jul 16, 2016

My log contains this:
/?FROM_REPO=eventhubutils&TO_REPO=eventhubutils&PULL_REQUEST_USER_DISPLAY_NAME=PRDAQCC1&EVERYTHING_URL=BUTTON_TRIGGER_TITLE=&INJECTION_URL_VALUE=&PULL_REQUEST_ACTION=OPENED...

I think you should just remove EVERYTHING_URL= from your URL. This should work:
https:///job/eventhubutils_Build_mvn/buildWithParameters?FROM_REPO=${PULL_REQUEST_FROM_REPO_NAME}&TO_REPO=${PULL_REQUEST_TO_REPO_NAME}&PULL_REQUEST_USER_DISPLAY_NAME=${PULL_REQUEST_USER_DISPLAY_NAME}&${EVERYTHING_URL}

@shlomipm
Copy link
Author

shlomipm commented Jul 16, 2016

Thank you for your quick reply,
i just sent you another URL, can you please tell me what you got?
http://cogi.bjurr.se/?url=${PULL_REQUEST_TO_SSH_CLONE_URL}&branches=pr/${PULL_REQUEST_TO_BRANCH}&sha1=${PULL_REQUEST_FROM_HASH}&PULL_REQUEST_URL=${PULL_REQUEST_URL}&PULL_REQUEST_ID=${PULL_REQUEST_ID}

It seems that the plugin send Parameters but why Jenkins job not receiving them?
https://{my Jankins server}/job/{job name}/buildWithParameters?FROM_REPO=${PULL_REQUEST_FROM_REPO_NAME}&TO_REPO=${PULL_REQUEST_TO_REPO_NAME}&PULL_REQUEST_USER_DISPLAY_NAME=${PULL_REQUEST_USER_DISPLAY_NAME}

FROM_REPO,TO_REPO,PULL_REQUEST_USER_DISPLAY_NAME - text parameters in the job.

Do you have experience with sending parameters to Jenkins jobs?

@tomasbjerre
Copy link
Owner

/?url=ssh%3A%2F%2Fgit%40bebitbucket1.cloudapp.net%3A7999%2Fop%2Feventhubutils.git&branches=pr/dev&sha1=a9f46ec306daff283f67515c2c0efbf2da6de4f6&PULL_REQUEST_URL=http%3A%2F%2Fbebitbucket1.cloudapp.net%3A7990%2Fprojects%2FOP%2Frepos%2Feventhubutils%2Fpull-requests%2F34&PULL_REQUEST_ID=34

If you simply browse to that URL with Chrome or something. Does that work?

@shlomipm
Copy link
Author

shlomipm commented Jul 16, 2016

No, it supposed to trigger a job in Jenkins,
What i'm trying to do is to trigger a job on Jenkins with parameters

https://{my Jankins server}/job/{job name}/buildWithParameters?FROM_REPO=${PULL_REQUEST_FROM_REPO_NAME}&TO_REPO=${PULL_REQUEST_TO_REPO_NAME}&PULL_REQUEST_USER_DISPLAY_NAME=${PULL_REQUEST_USER_DISPLAY_NAME}

The trigger is working, the variables are moving from Bitbucket (as you are getting them) but the Parameters in the job that supposed to be set by the variables from Bitbucket stays BLANK.

For testing: if i'm sending this url:
https://{my Jankins server}/job/{job name}/buildWithParameters?FROM_REPO=fromrepotest&TO_REPO=torepotest&PULL_REQUEST_USER_DISPLAY_NAME=myusername
all is working, so i don't know if it is a Jenkins side issue.

@tomasbjerre
Copy link
Owner

If you add a shell script build step, and execute env it should printout all parameters. Does it contain your parameters?

@shlomipm
Copy link
Author

lets make some order.
'env' is nothing to do here because those are 'Parameters' and not 'Environment Variables' so i insert a shell script to 'echo' them.

for testing i'm using the next url:
https://bejenkins1.cloudapp.net:8443/job/eventhubutils_Build_mvn/buildWithParameters?FROM_REPO=fromrepotest&TO_REPO=torepotest&PULL_REQUEST_USER_DISPLAY_NAME=myusername

when i'm inserting it directly in the browser - Jenkins is triggered and all the Parameters are in.
when i'm sending it with the plugin (post method) - Jenkins is triggered but no parameters are set.

maybe credentials issue?
(can we chat over skype to be more quick?)

@tomasbjerre
Copy link
Owner

The parameters should be exposed as environment variables, it says so here.

So you use POST method as request method in the plugin? If you add the parameters in the URL you must use GET. Selecting GET should be equivalent to this:

curl -u username:password 'https://bejenkins1.cloudapp.net:8443/job/eventhubutils_Build_mvn/buildWithParameters?FROM_REPO=fromrepotest&TO_REPO=torepotest&PULL_REQUEST_USER_DISPLAY_NAME=myusername'

And if you actually want to use POST method. I would try adding this to post content field and remove it from the URL:

FROM_REPO=${PULL_REQUEST_FROM_REPO_NAME}&TO_REPO=${PULL_REQUEST_TO_REPO_NAME}&PULL_REQUEST_USER_DISPLAY_NAME=${PULL_REQUEST_USER_DISPLAY_NAME}

@shlomipm
Copy link
Author

Where do i need to run the curl command (does it matter?) and what do i supposed to get in return?
(currently i;m getting a lot of html lines and nothing happens in the Jenkins side).

@tomasbjerre
Copy link
Owner

Im not 100% that the curl comman is correct. But something lika that should
trigger a build. It may helt troubleshooting. And did you change
username:password to a valid one?

Do you use GET method in the plugin?

Den 16 juli 2016 11:30 skrev "Shlomi Perets" [email protected]:

Where do i need to run the curl command (does it matter?) and what do i
supposed to get in return?
(currently i;m getting a lot of html lines and nothing happens in the
Jenkins side).


You are receiving this because you commented.

Reply to this email directly, view it on GitHub
#132 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAa1ExNa12qxpwwZd1rGHw7lVQHiXn-cks5qWKSwgaJpZM4JNf-f
.

@mihirsoni
Copy link

@tomasbjerre In my case It is not at all triggering anything from bitbucket. I am using bitbucket 4.7.1

@mihirsoni
Copy link

When I use this command

$ curl -u username:passwd 'http://localhost:7990/bitbucket/rest/prnfb-admin/1.0/settings/notifications' -H 'Accept: application/json, text/javascript, */*; q=0.01'

I get response as

{"message":"null for uri: http://localhost:7990/rest/api/1.0/bitbucket/rest/prnfb-admin/1.0/settings/notifications","status-code":404}%

@tomasbjerre
Copy link
Owner

You should open another issue about that. This issue is not about this
plugin at all. It works as expected. Your case might be about the plugin.

Den 18 juli 2016 09:03 skrev "Mihir Soni" [email protected]:

When I use this command

$ curl -u username:passwd 'http://localhost:7990/bitbucket/rest/prnfb-admin/1.0/settings/notifications' -H 'Accept: application/json, text/javascript, /; q=0.01'

I get response as

{"message":"null for uri: http://localhost:7990/rest/api/1.0/bitbucket/rest/prnfb-admin/1.0/settings/notifications","status-code":404}%


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#132 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAa1E81Gi7E7FnwwdOQG5YqE-estwNYhks5qWyVEgaJpZM4JNf-f
.

@tomasbjerre tomasbjerre changed the title Bitbucket 4.7.1 and Jenkins 2.1 How to trigger Jenkins 2.1 with parameters Jul 18, 2016
@tomasbjerre tomasbjerre added question and removed bug labels Jul 18, 2016
@mihirsoni
Copy link

@tomasbjerre As mentioned , I have created issue #133

@tomasbjerre
Copy link
Owner

I rewrote the documentation in the README does that help?

It took me a while but I managed to trigger Jenkins 2.2 now!

@tomasbjerre
Copy link
Owner

Open issue again if any problems.

@alinkamalinkakalinka
Copy link

Hi! I have the same issue as well. I try to trigger Jenkins job with https://jenkins/job/pull%20request_builder/buildWithParameters?FROM_REPO=${PULL_REQUEST_FROM_REPO_NAME}. I tried both POST and GET, unfortunately the job is triggered but parameters' values are blank and not listed as env variables. Could you help me please? Thank you in advance.
screen shot 2018-10-30 at 16 58 55

screen shot 2018-10-30 at 17 03 16

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants