Skip to content

Instantly share code, notes, and snippets.

@serafeimgr
Created October 4, 2019 09:45
Show Gist options
  • Save serafeimgr/500406447bc4e4d1884ef0027b330dc9 to your computer and use it in GitHub Desktop.
Save serafeimgr/500406447bc4e4d1884ef0027b330dc9 to your computer and use it in GitHub Desktop.
jenkins-config.sh
#!/bin/bash
# Jenkins Configurations Directory
cd $JENKINS_HOME
# make sure we're in a git working directory
if [ ! -d .git ]; then
echo "error: there is no .git directory here. Make sure you're in the right place."
exit 1
fi
# Try and pull changes. Any changes here Would indicate that someone manually
# edited the config outside of jenkins and pushed. Hopefully this is not a
# problem :)
git pull
# Only add job credentials if they exist
find -regex '\./jobs/.*/.*\.credentials' -print0 | xargs -r -0 git add
# only add user configurations if they exist
if [ -d users ]; then
user_configs=`ls users/*/config.xml`
if [ -n "$user_configs" ]; then
git add users/*/config.xml
fi
fi
# Add general configurations, job configurations, and user content
git add -- *.xml jobs/*/*.xml userContent/* \
plugins/*.jpi* plugins/*.hpi*
# Add various credentials
git add -- *.key* secrets
# mark as deleted anything that's been, well, deleted
git ls-files --deleted -z | xargs -r -0 git rm
# Commit if there is anything to commit
git diff --exit-code && git diff --cached --exit-code ||\
git commit -m "Automated Jenkins commit"
# And push
git push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment