Skip to content

Instantly share code, notes, and snippets.

@aussielunix
Last active April 12, 2018 17:37
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save aussielunix/1919354 to your computer and use it in GitHub Desktop.
Save aussielunix/1919354 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="sj@example.com"
    export GIT_COMMITTER_NAME="Sir Jenkins"
    export GIT_COMMITTER_EMAIL="sj@example.com"
  • 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
@gustavs
Copy link

gustavs commented Feb 3, 2015

Hi!
I've tried to do it the other way around and ignore everything except XML-files, plugins and nextBuildNumber. This is what I ended up with. Just an idea :)

== .gitignore ==
*
!README
!.gitignore
!.xml
!nextBuildNumber
!jobs
!jobs/

!plugins
!plugins/*.jpi

== Script ==
git add -A
git commit -m "Config backup"
git push

@aussielunix
Copy link
Author

THANKS !

I have now updated the original gist based on your information.
I found a bug in the shell script/periodic job too so that has been updated.

@romk1n
Copy link

romk1n commented Aug 31, 2016

@aussielunix what about workspace folder? do you push to github as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment