Created
October 4, 2019 09:45
-
-
Save serafeimgr/500406447bc4e4d1884ef0027b330dc9 to your computer and use it in GitHub Desktop.
jenkins-config.sh
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
#!/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