Skip to content

Instantly share code, notes, and snippets.

@btamayo
Created September 12, 2020 22:44
Show Gist options
  • Save btamayo/fd09dbe8bb22e860bab60370692fc538 to your computer and use it in GitHub Desktop.
Save btamayo/fd09dbe8bb22e860bab60370692fc538 to your computer and use it in GitHub Desktop.
Download GDSL for Jenkins jobs to import into IntelliJ
#!/usr/bin/env bash
# Pretty rough script on downloading GDSLs. Replace http://localhost:8080 with your Jenkins URL. You may have to
# provide an authtoken.
jobs_curl=$(curl --silent --location --request GET 'http://localhost:8080/api/json?tree=jobs\[name\]')
list=$(jq --raw-output '.jobs[] | .name' <<< "$jobs_curl")
write_gdsl_file() {
mkdir -p "gdsls"
if [[ -z $1 || -z $2 ]]; then
return
fi
touch "gdsls/$1.gdsl"
printf "%s" "$2" > "gdsls/$1.gdsl"
}
get_gdsl () {
if [[ -z $1 ]]; then
echo "ERROR: job name not provided"
return
fi
job_name=$1
gdsl_url="http://localhost:8080/job/$job_name/pipeline-syntax/gdsl"
status_code=$(curl --write-out %{http_code} --silent --output /dev/null $gdsl_url)
if [[ "$status_code" -ne 200 ]] ; then
echo "HTTP status for job name $job_name is $status_code"
else
gdsl_job=$(curl -s --location --request GET $gdsl_url)
write_gdsl_file "$job_name" "$gdsl_job"
fi
}
echo "$list" | while read -r line; do
get_gdsl "$line"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment