Pipelines in Git
Version control the pipelines
On the previous page, you learned how to edit pipelines using the Jenkins web interface. However, the real strength of infrastructure-as-code comes into play when we store pipelines in version control, to audit and control changes.
We recommend using Git for version control; if you want to know why head over to our Git guide.
Using a pipeline from GitHub
Make sure you have git installed before proceeding.
In Jenkins click New Item to create a new job, and choose Pipeline just like before. Click OK to continue and scroll down to the bottom of the configuration window.
Rather than copying the pipeline code into the script box, select Pipline script from SCM. You will then need to enter the Repository URL of the git repository that contains the pipeline. Our basic pipeline example is hosted publicly on github. Copy and paste this address into the Repository URL box:
You do not need to add any Credentials at this time, because we are only cloning the pipeline and not modifying it.
Finally, you need to edit the Script Path to be the correct name of the pipeline:
Once you have done all of that, the configuration window should look like this:
Click Save followed by Build Now in order to run the pipeline. It should look very similar to the first example, but with an extra stage that performs the pipeline checkout from git at the beginning.
If you click on the first stage box and then click Logs you will see the log of git cloning the pipeline from github: