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
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
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']
.Location
header pointing to the queue item or build status URL after the job is triggered.Location
header, the Jenkins API responds with an HTTP 302 redirect to the job URL and no further details.
Verified Jenkins API Response:
curl
request to trigger the job:curl -X POST -u "$JENKINS_USER:$JENKINS_API_TOKEN" "https://jenkins.abccompany.com.au/job/dev-multi-branch-pipeline/build"
Location
header.Adjusted Pipeline Configuration:
JOB_NAME
is correctly pointing to the multi-branch pipeline.Checked Jenkins Logs:
jenkins.log
.Updated Plugins:
Verified CSRF Settings:
Tried Alternative API Endpoints:
Location
header missing in the Jenkins API response?jenkins-job-trigger
pipe?Hello @Jam Nadeem ,
and welcome to the Community!
It may be that Jenkins is redirecting the request to the login page because the credentials are incorrect. When you sent a manual request using curl and received an HTTP 302 (redirect), did the job on Jenkins correctly trigger? What is the URL it's redirecting you to?
Also, the Location header might not be supported in case you're using a considerably old version of Jenkins. Could you confirm which exact Jenkins version you're using ?
Thank you, @Jam Nadeem !
Patrik S
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's great @Jam Nadeem .
If you feel comfortable in sharing the solution here in the community, feel free to do so, as it can help other users that may come across the same issue in the future.
Thank you, @Jam Nadeem !
Patrik S
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Patrik SI identified and fixed an issue in the Bitbucket pipeline script where the JOB_NAME
prefix was incorrect.
Incorrect Format:JOB_NAME: "job/dev-multi-branch-pipeline/"
Correct Format:JOB_NAME: "job/dev-multi-branch-pipeline/job/$BITBUCKET_BRANCH"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Awesome! Really appreciate your time in sharing the solution here :)
If you ever need help in the future, feel free to reach out to the community!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.