Api access of finished build's build.xml

Is there a way to get the info stored in build.xml of a completed build?

I know about $JENKINS_URL/job/JOB/BUILD_ID/api/json but that does not have the same information.

Other than loading from the filesystem $JENKINS_HOME/jobs/JOB/builds/ID/build.xml, is there a way to get it through the api?

Thanks!

I believe you can do build.xml instead of /API/JSON

Pretty curious why you’d need the raw XML though.

This information is the private serialization of a build and is hopefully not accessible via API. What information is missing? Each build participant can make more values public if it makes sense.

I tried $JENKINS_URL/job/JOB/BUILD_ID/build.xml but got 403

build.xml has the full trace of build causes; whereas api/json gives you the build causes just one level above. I know I can get the same info by tracing through the layers but build.xml has all the work done.

build.xml has ‘workspace’ but not api/json. I could get PWD from injectedVars but it’s not always the same as $WORKSPACE.

how would you make $WORKSPACE public?

Look at the parent node of the not accessible data in the build.xml, then you see which plugin stores that information. Create an issue (or even better a PR that adds a corresponding @Exported annotation) for the affected plugin.

How do I create a PR?

the parent of “workspace” is just “build”

I like to get build/actions/hudson.model.CauseAction too:

Then the property is directly available in the build class:

Please note that this property is not available for pipelines, just for Freestyle jobs.

See https://github.com/jenkinsci/jenkins/blob/01b28f3fcca47bfdb49f97ae86fcf30bf9fb37e2/CONTRIBUTING.md

Maybe it helps if you can elaborate why you want that kind of information?

Lets say a build needs to copy the current workspace of its upstream ancestor. This probably shouldn’t happened in the Jenkins model but that’s the way it’s been setup in our environment long ago.

I’m trying to get the WORKSPACE of an upstream build, not the current build. Is that possible? Yes I am using Freestyle jobs.