Deploy configs from Git with Jenkins

Sometimes its useful to save the config for a Projekt in a GIT-Projekt and automatic deploy to a Server with a Jenkins.

For some Projekts I have saved the configuration inside a GIT-Projekt. The Git-Projekt is connected with a Jenkins so that if a change is pushed to the Server the config go direct to the System.  I want to show you how I do it at an example with nagios for Server-Monitoring. 

After i install nagios on a new Server I downloaded the Sample-Config. I removed some "useless" Files (e.g. the windows-monitoring, i don't need it). After this I create a new Git Projekt (a private one at my selfhostet bitbucket instanz).

After this I add some basic checks for example if all Webpages are online and other Stuff. Also I create a "scripts" folder where I saved a script to send notification via Postmarkapp. The next thing to do is install a Jenkins, for my private usage I have a Jenkins inside a Docker-Container. To connect Bitbucket with Jenkins I used the Webhook to Jenkins for Bitbucket Plugin. Before you aktivate the Jenkins Trigger in Bitbucket you need to create the Projekt in Jenkins. Give a Jenkins-User access (at least read access) to the Projekt. If you use this Plugin you need to aktivate the "Source Code Management System" as Build-Trigger in Jenkins. Saved it and activate the Trigger in Bitbucket, if it works the Job will run after you comit something. 

For a really installation you can use the SSH2Easy Plugin in Jenkins. The Plugin can connect to SSH-Server with Username/Passwort Auth. But there are also other Plugins for Certificat-Auth. You have two ways to push the config to the Server. One way is to zip (or tar.gz or whatever you like) the config from the Jenkins Workingspace and push it via ssh to the Server. The other way is just to connect to the Server and pull the config in any folder.

At the Server I removed the orginal config Folder and create a symbolic link the the Git-Projekt folder or in my case a sub-folder of the Git-Projekt.

With this configuration its really easy to update the config from any locale Computer. I don't need to connect to any server manual just push it to the Git. Also I could use the Web-Gui from bitbucket to change the config. You can do this with nearly all kind of Software on Linux-Server. You need to decide based on the case if it usefull to auto-deploy the config. Its easy, you can give more people "access" to the config, you can see older Version of the config.




Veröffentlicht: 01.11.2017