Skip to content

Instantly share code, notes, and snippets.

@stefancrain
Last active April 6, 2017 15:41
Show Gist options
  • Save stefancrain/514526e2665dd125a9311600ca9d36f7 to your computer and use it in GitHub Desktop.
Save stefancrain/514526e2665dd125a9311600ca9d36f7 to your computer and use it in GitHub Desktop.
Backup up all Jenkins jobs as XML
#!/bin/bash
HOST="JENKINS_URL"
PORT="8443"
URL="http://USERNAME:APIKEY@$HOST:$PORT"
folder=$(date +%Y%m%d-%H%M%S)
mkdir -p "$HOST/$folder"
while read job
do
echo "Job: '$job'";
java -jar ~/Downloads/jenkins-cli.jar -s "$URL" get-job "$job" > "$HOST/$folder/$job".xml
done < <(java -jar ~/Downloads/jenkins-cli.jar -s "$URL" list-jobs 2> /dev/null)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment