Auditing Durability in Jenkins Jobs
Something that came up with one of my customers was the ability to audit Durability settings for Pipelines in Jenkins. The main use case was, that once Durability was set globally, is there a way to look into jobs and find out if they’re using the global Durability setting or something else. This would enable the customer to check-in and ensure Durability is enforced and used correctly in different settings by those who have specifically discussed it with the owner of the Controller.
The below script is designed to check jobs in your
JENKINS_HOME directory (specify it on line 3); from there it will check each job’s latest log for Durability and return the job name and Durability level in the command line.
This has only been tested in limited capacity and may need extra retooling to suit your needs.
# Assumes your JENKINS_HOME is set properly JENKINS_HOME=/var/lib/cloudbees-core-cm cd "$JENKINS_HOME/jobs/" for file in */ ; do cd "$JENKINS_HOME/jobs/" # Gets the job name as the directory without a trailing slash jobname=$(echo "$file" | sed 's:/*$::') echo "*** Job name is \"$jobname\" ($file)" cd "$JENKINS_HOME/jobs/$jobname/builds" job_number=$(ls -1dt */ | head -n 1) job_durability=$(cat "$JENKINS_HOME/jobs/$jobname/builds/$job_number/log" | sed -n -e 's/^.*Durability level: //p') echo "Job \"$jobname\" is set to $job_durability"; doneCode language: Bash (bash)