Skip to content

Instantly share code, notes, and snippets.

@ralph-tice
Last active September 28, 2017 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ralph-tice/7139341 to your computer and use it in GitHub Desktop.
Save ralph-tice/7139341 to your computer and use it in GitHub Desktop.
version control jenkins and jobs this shell snippet itself can be used as a jenkins job and it will add itself.
cd /var/lib/jenkins
git add userContent/* -f
git add jobs/*/*.xml -f
git add users/*/config.xml -f
git add *.xml
COUNT=`git ls-files --deleted | wc -l`
if [ $COUNT -ne 0 ]
then git ls-files --deleted | xargs -d '\n' git rm
fi
git commit -m "autocommit by jenkins job because $BUILD_CAUSE"
# Push the commit up to the remote repository.
git push origin ci
@ralph-tice
Copy link
Author

this is a dupe of https://gist.github.com/ralph-tice/9842bbddd68b1797b63f
not sure why i made it again, but i added the bug fix to the original

@ralph-tice
Copy link
Author

ralph-tice commented Sep 28, 2017

Now that AWS has Code Commit, this is a pretty compelling way (IMO) to persist Jenkins config for legacy deployments.

One step better is to use https://docs.openstack.org/infra/jenkins-job-builder/

An order of magnitude better is to use Jenkins Pipelines, https://jenkins.io/doc/book/pipeline/ -- a decent bullet point overview of a comprehensive implementation is here: http://slides.com/rocktavious/uacf-ci#/

@ralph-tice
Copy link
Author

Hmm, this is missing the git init side of the automation and setting up the git remote, in 2013 I probably did that manually since I only had a single Jenkins master. This should be illustrative enough of the concept still, but caveat emptor.

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