The Problem
Recently, I was attempting to trigger a Jenkins job via webhook (just like the UI tells you is possible). Unfortunately, even with the authorization token, my request would be 401'd (unauthorized) and sent over to single sign-on. I am shocked that there is no way to bypass SSO login when calling a webhook and providing an authorization token.
The Solution
Thankfully, there is a way!
- Login to your Jenkins instance as an admin.
- Install the Build Authorization Token Root plugin found here.
- Once installed, browse to the Jenkins job that you wish to trigger via a webhook.
- Click Configure.
- Under Build Triggers, check the Trigger Builds Remotely checkbox.
- Set an authentication token here.
- Save the job.
- You can now kick off your job with the following URL:
https://<Jenkins host>/buildByToken/build?job=<job name>&token=<token from step 6>
Note
If your job name has spaces in it, replace those spaces with %20.