Can I export, in any conventional file format, a history of builds, with their time/date and success. And hopefully even promotion status.
Export the jobStep 1- Open Jenkins and Go to the job which you want to export. Notes- We will use some commands which will help us to do our job. get-job- this will export the job in XML file. create-job – this will import the job from XML and will create job in Jenkins.
Export Report: Finalize Run Info: Specify a filename for the ZAP Report. Note that the file extension is not necessary. The report(s) will be saved into the Jenkins Job's Workspace. Info: Append the Build Variable BUILD_ID to the filename to ensure a quality name.
Get a list of jobs. This can be done requesting http://jenkins_url:port/api/json?tree=jobs[name,url] .
You can make use of Jenkins rest api :
http://JENKINS_URl/api/json?tree=jobs[name,url]
http://JENKINS_URL/job/JOB_NAME/api/json?tree=allBuilds[number,url]
http://JENKINS_URL/job/JOB_NAME/BUILD_NUMBER/api/json
For automation, you can use bash, curl and jq to achieve this.
Have written small bash script to retrieve build status and timestamp for each job on Jenkins server :
#!/bin/bash
JENKINS_URL=<YOUR JENKINS URL HERE>
for job in `curl -sg "$JENKINS_URL/api/json?tree=jobs[name,url]" | jq '.jobs[].name' -r`;
do
echo "Job Name : $job"
echo -e "Build Number\tBuild Status\tTimestamp"
for build in `curl -sg "$JENKINS_URL/job/$job/api/json?tree=allBuilds[number]" | jq '.allBuilds[].number' -r`;
do
curl -sg "$JENKINS_URL/job/$job/$build/api/json" | jq '(.number|tostring) + "\t\t" + .result + "\t\t" + (.timestamp|tostring)' -r
done
echo "================"
done
Note : Above script assumes that Jenkins server does not have any authentication. For authentication, add below parameter to each curl call :-u username:API_TOKEN
Where :username:API_TOKEN with your username and password/API_Token
Similar way you can export all build history in any format you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With