Skip to content

Instantly share code, notes, and snippets.

@OlegGorj
Created August 7, 2018 12:36
Show Gist options
  • Save OlegGorj/004af5c215f4108e34c56e5336b25517 to your computer and use it in GitHub Desktop.
Save OlegGorj/004af5c215f4108e34c56e5336b25517 to your computer and use it in GitHub Desktop.
jenkins configs to github
*
!/.gitignore
!/*.xml
!/nextBuildNumber
!/jobs
!/jobs/*
!/jobs/*/*.xml
/jobs/*/disk-usage.xml
/jobs/*/builds
!/users
!/users/**/
!/users/**/*.xml

Storing jenkins Configs in Github

This is current as of Jenkins LTS (1.580.3)

  • create a .gitignore file in your $JENKINS_HOME with the following
  • this may need tuning to your liking
  • ie storing artifacts etc
  • setup some ENV variables for the user that jenkins runs under.
  • I add the following to /home/jenkins/.bashrc
  • and restart jenkins
    export GIT_AUTHOR_NAME="Sir jenkins"
    export GIT_AUTHOR_EMAIL="[email protected]"
    export GIT_COMMITTER_NAME="Sir Jenkins"
    export GIT_COMMITTER_EMAIL="[email protected]"
  • create a new Jenkins periodic job with this bash script.

#!/bin/bash -e
# Jenkins Configuraitons Directory
cd $JENKINS_HOME
# set git details etc
source .bashrc
git_status="`git status -unormal 2>&1`"
if [[ "$git_status" =~ Not\ a\ git\ repo ]]; then
echo
echo "NOT A GIT REPOSITORY"
echo
exit 1
elif [[ "$git_status" =~ nothing\ to\ commit ]]; then
echo
echo "NOTHING CHANGED !"
echo
exit 0
else
git add --all .
git commit -am "Automated Jenkins commit"
git push -q origin master
exit 0
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment