You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 9, 2021. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+40-5Lines changed: 40 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -145,15 +145,50 @@ It will respond with something like this.
145
145
You may use Chrome and Developer Tools (press F12) to view rest calls while editing in GUI to find more examples.
146
146
147
147
### Jenkins
148
-
Parameterized Jenkins jobs can be triggered remotely via:
148
+
Parameterized Jenkins jobs can be triggered remotely by invoking a URL. How you trigger your Jennkins installation may vary depending on how it is configured. Here is, probably, the most complicated scenario where there is CSRF protection and authentication requirements.
149
+
150
+
The job that you want to trigger must have:
151
+
**This build is parameterized* checkbox checked.
152
+
**Trigger builds remotely* checkbox checked.
153
+
* You may, or may not, use a token here.
154
+
155
+
I like to add an *Execute shell* build step and then just do `echo param: $paramName` to test that my parameter shows up in the build job log.
156
+
157
+
First, you may try to trigger Jenkins with [Curl](https://github.com/curl/curl) from command line and then, when you know how it should be done, configure the plugin.
158
+
159
+
If your Jenkins is CSRF protected, you need to get a crumb. It can be done like this.
If you are using a CSRF protection in Jenkins, you can use the **Injection URL** feature.
154
-
* Set **Injection URL** field to `http://JENKINS/crumbIssuer/api/xml?xpath=//crumb/text()`. You may get an error like *primitive XPath result sets forbidden; implement jenkins.security.SecureRequester*. If so, you can set Injection URL to `http://JENKINS/crumbIssuer/api/xml?xpath=//crumb` in combination with regular expression `<crumb>([^<]*)</crumb>`. Or a third option is to checkout [this](https://wiki.jenkins-ci.org/display/JENKINS/Secure+Requester+Whitelist+Plugin) Jenkins plugin.
155
-
* In the headers section, set header **.crumb** with value **${INJECTION_URL_VALUE}**.
164
+
The response should be something like `Jenkins-Crumb:f122c77298b349b0116140265418ec7f`.
165
+
166
+
Now you can trigger a build like this (just remove `?token=YOUR_TOKEN` if you are not using a token).
167
+
168
+
```
169
+
curl -u USERNAME:PASSWORD -X POST --data "paramName=paramValue" -H "Jenkins-Crumb:f122c77298b349b0116140265418ec7f" http://JENKINS_HOSTNAME/job/JENKINS_JOB/buildWithParameters?token=YOUR_TOKEN
170
+
```
171
+
172
+
Now that job should have been triggered and you should be able to verify that Jenkins is setup correclty. You may want to SSH to the Bitbucket Server machine and do this, to also verify that firewalls are open.
173
+
174
+
Now to configure the plugin!
175
+
176
+
If you need ***authentication***, add your username and password in *Basic authentication*.
177
+
178
+
If you are using a ***CSRF*** protection in Jenkins, you can use the **Injection URL** feature.
179
+
* Set **Injection URL** field to `http://JENKINS_HOSTNAME/crumbIssuer/api/xml?xpath=//crumb/text()`.
180
+
* You may get an error like *primitive XPath result sets forbidden; implement jenkins.security.SecureRequester*. If so, you can set Injection URL to `http://JENKINS/crumbIssuer/api/xml?xpath=//crumb` in combination with regular expression `<crumb>([^<]*)</crumb>`.
181
+
* A third option is to checkout [this](https://wiki.jenkins-ci.org/display/JENKINS/Secure+Requester+Whitelist+Plugin) Jenkins plugin.
182
+
* In the headers section, set header **Jenkins-Crumb** with value **${INJECTION_URL_VALUE}**. The `Jenkins-Crumb` header name was previously just `.crumb`, use whatever the `curl` command responded with above.
183
+
184
+
You may trigger the build with `GET` or `POST`.
185
+
186
+
In ***URL*** add `http://JENKINS_HOSTNAME/job/JENKINS_JOB/buildWithParameters?token=YOUR_TOKEN¶mName=paramValue`.
156
187
188
+
Thats it! There are some common mistakes.
189
+
* If using ${EVERYTHING_URL}, like `...?token=token&${EVERYTHING_URL}` then in your jenkins job you have to have parameters for each parameter, like `PULL_REQUEST_URL`.
190
+
* Even when using `POST`, you should add the parameters to the `URL`.
191
+
157
192
## Reporting issues
158
193
If things don't work as you expect, perhaps you should file an issue. But first, try troubleshooting it and provide as much info as possible. Here are some things that may help if added to an issue.
0 commit comments