Last active
November 5, 2021 11:47
-
-
Save jlamoree/190981413b9ee44bbd086b28d24dd44a to your computer and use it in GitHub Desktop.
Export Jenkins Configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash -eu | |
project_root="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )" | |
lib_dir="${project_root}/lib" | |
source "${project_root}/scripts/vars.sh" | |
jenkins-cli() { | |
java -jar "${lib_dir}/jenkins-cli.jar" -webSocket $@ | |
} | |
jenkins-cli list-jobs > "${project_root}/jobs/inventory" | |
for job in $(cat "${project_root}/jobs/inventory"); do | |
test -z "$job" && continue | |
jenkins-cli get-job "$job" > "${project_root}/jobs/${job}.xml" | |
echo "Exported job: $job" | |
done | |
echo 'jenkins.model.Jenkins.get().computers.each { println "${it.node.selfLabel.name}" }' | \ | |
jenkins-cli groovy = | \ | |
tr A-Z a-z | sed -e '/^master$/d;/^$/d' > "${project_root}/nodes/inventory" | |
for node in $(cat "${project_root}/nodes/inventory"); do | |
test -z "$node" && continue | |
jenkins-cli get-node "$node" > "${project_root}/nodes/${node,,}.xml" | |
echo "Exported node: $node" | |
done | |
echo 'jenkins.model.Jenkins.get().views.each { println "${it.name}" }' | \ | |
jenkins-cli groovy = | \ | |
sed -e '/^all$/d;/^$/d' > "${project_root}/views/inventory" | |
for view in $(cat "${project_root}/views/inventory"); do | |
test -z "$view" && continue | |
jenkins-cli get-view "$view" > "${project_root}/views/${view,,}.xml" | |
echo "Exported view: $view" | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export JENKINS_URL="https://jenkins.pizza" | |
if [ "_$JENKINS_USER_ID" == "_" ]; then | |
echo "Missing environment variable JENKINS_USER_ID" | |
exit 1 | |
fi | |
if [ "_$JENKINS_API_TOKEN" == "_" ]; then | |
echo "Missing environment variable JENKINS_API_TOKEN" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment