Description:
I’m encountering an issue while triggering a Jenkins multi-branch pipeline from a Bitbucket Cloud pipeline using the atlassian/jenkins-job-trigger pipe. The pipeline fails with a KeyError: 'Location' when attempting to retrieve the Location header from the Jenkins API response. Below are the detailed logs, pipeline configuration, and troubleshooting steps I have tried so far.
Pipeline Script

Bitbucket Pipeline Error

Error Logs:
Below are the detailed logs captured during the pipeline execution:
INFO: None INFO: Submitting jenkins job... DEBUG: Starting new HTTPS connection (1): jenkins.abccompany.com.au:443 DEBUG: https://jenkins.abccompany.com.au:443 "POST /job/dev-multi-branch-pipeline/build HTTP/11" 302 0 DEBUG: https://jenkins.company.com.au:443 "GET /job/dev-multi-branch-pipeline/ HTTP/11" 200 None Traceback (most recent call last): File "/pipe.py", line 200, in <module> pipe.run() File "/pipe.py", line 191, in run self.wait_for_job(build_response.headers['Location']) File "/usr/local/lib/python3.10/site-packages/requests/structures.py", line 52, in __getitem__ return self._store[key.lower()][1] KeyError: 'location' N/A: version "v21.1.0" is not yet installed
Issue Details:
- Problem: The
atlassian/jenkins-job-trigger pipe expects a Location header in the response from Jenkins, but this header is missing. The pipe fails when attempting to access build_response.headers['Location']. - Expected Behavior: Jenkins should return a
Location header pointing to the queue item or build status URL after the job is triggered. - Observed Behavior: Instead of the expected
Location header, the Jenkins API responds with an HTTP 302 redirect to the job URL and no further details.
Troubleshooting Steps Tried:
Verified Jenkins API Response:
- Sent a manual
curl request to trigger the job:bash
curl -X POST -u <span>"<span>$JENKINS_USER</span>:<span>$JENKINS_API_TOKEN</span>"</span> <span>"<a href="https://jenkins.heartbug.com.au/job/dev-multi-branch-pipeline/build" rel="noopener nofollow noreferrer" target="_blank">https://jenkins.abccompany.com.au/job/dev-multi-branch-pipeline/build</a>"</span>
- Observed an HTTP 302 response with no
Location header.
Adjusted Pipeline Configuration:
- Verified that
JOB_NAME is correctly pointing to the multi-branch pipeline.
Checked Jenkins Logs:
- No errors related to API requests or authentication were found in
jenkins.log.
Updated Plugins:
- Ensured the following plugins are up-to-date:
- Pipeline: Multi-branch
- Bitbucket Branch Source
- REST API Plugin
Verified CSRF Settings:
- Checked that CSRF protection is enabled and tested with both tokens and crumbs. No difference in behavior was observed.
Tried Alternative API Endpoints:
- Attempted to query queue items directly, but the expected build process did not start.
Questions/Help Needed:
- Why is the
Location header missing in the Jenkins API response? - Is this a known issue with Jenkins' handling of multi-branch pipelines when triggered via the REST API?
- Are there any workarounds or alternative methods to reliably trigger and monitor Jenkins multi-branch pipeline jobs from Bitbucket Cloud?
- Could this be a misconfiguration in Jenkins or a limitation of the
jenkins-job-trigger pipe?