As I have mentioned my previous post about Getting started with Gitlab-CI for Network Automation, Jenkins is another continuous integration pipelining tool you can use for network automation. Have a look about how to install Jenkins: https://wiki.jenkins.io/display/JENKINS/Installing+Jenkins+on+Ubuntu
To use the Jenkins with Vagrant and KVM (libvirt) there are a few changes needed on the linux server similar with the Gitlab-Runner. The Jenkins user account needs to be able to control KVM and you need to install the vagrant-libvirt plugin:
usermod -aG libvirtd jenkins sudo su jenkins vagrant plugin install vagrant-libvirt
Optional: you may need to copy custom Vagrant boxes into the users vagrant folder ‘/var/lib/jenkins/.vagrant.d/boxes/*’. Note that the Jenkins home directory is not located under /home.
Now lets start configuring a Jenkins CI-pipeline, click on ‘New item’:
This creates an empty pipeline where you need to add the different stages of what needs to be executed:
Below is an example Jenkins pipeline script which is very similar to the Gitlab-CI pipeline I have used with my Cumulus Linux Lab in the past.
pipeline { agent any stages { stage('Clean and prep workspace') { steps { sh 'rm -r *' git 'https://github.com/berndonline/cumulus-lab-provision' sh 'git clone --origin master https://github.com/berndonline/cumulus-lab-vagrant' } } stage('Validate Ansible') { steps { sh 'bash ./linter.sh' } } stage('Staging') { steps { sh 'cd ./cumulus-lab-vagrant/ && ./vagrant_create.sh' sh 'cd ./cumulus-lab-vagrant/ && bash ../staging.sh' } } stage('Deploy production approval') { steps { input 'Deploy to prod?' } } stage('Production') { steps { sh 'cd ./cumulus-lab-vagrant/ && ./vagrant_create.sh' sh 'cd ./cumulus-lab-vagrant/ && bash ../production.sh' } } } }
Let’s run the build pipeline:
The stages get executed one by one and, as you can see below, the production stage has an manual approval build-in that nothing gets deployed to production without someone to approve before, for a controlled production deployment:
Finished pipeline:
This is just a simple example of a network automation pipeline, this can of course be more complex if needed. It should just help you a bit on how to start using Jenkins for network automation.
Please share your feedback and leave a comment.