Skip to content

Instantly share code, notes, and snippets.

@alexandrebodin
Last active August 29, 2015 14:08
Show Gist options
  • Save alexandrebodin/3cea4ec83e4a6e5ebe80 to your computer and use it in GitHub Desktop.
Save alexandrebodin/3cea4ec83e4a6e5ebe80 to your computer and use it in GitHub Desktop.
jenkins configuration
# Move into the jenkins directory
cd /var/lib/jenkins
#test config params
[ -z "$jenkins_config_repo" ] && echo "Need to set jenkins_config_repo" && exit 1
[ -z "$jenkins_email" ] && echo "Need to set jenkins_email" && exit 1
#test if init necessary
if [ ! -d ".git" ];
then
git init
fi
#git user info
git config --global user.name "Jenkins"
git config --global user.email "$jenkins_email"
#if remote origin isn't present add it
REMOTE_COUNT=`git remote | grep origin | wc -l`
if [ $REMOTE_COUNT -le 0 ];
then
git remote add origin $jenkins_config_repo
fi
#reset origin url in case the configuration changed
git remote set-url origin $jenkins_config_repo
#Add all top level xml files.
git add *.xml
# Add all job config.xml files.
git add jobs/*/config.xml
# Add all user config.xml files.
git add users/*/config.xml
# Add all user content files.
git add userContent/*
# Remove files from the remote repo that have been removed locally.
COUNT=`git ls-files --deleted | wc -l`
if [ $COUNT -ne 0 ];
then
git ls-files --deleted | xargs git rm
fi
#count nb of files to commit
COMMIT_COUNT=`git diff --name-only --cached | wc -l`
#if there are files to commit
if [ $COMMIT_COUNT -gt 0 ];
then
# Commit the differences
git commit -m "Automated commit of jenkins chaos"
# Push the commit up to the remote repository.
git push origin master
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment