Jenkins Pipeline as Code
Harshad Ranganathan
Posted on May 12, 2019
Originally published at rharshad.com
Jenkins Pipeline is a suite of plugins which supports implementing and integrating continuous delivery pipelines into Jenkins.
Need for Jenkins Pipeline as Code
Over time, Jenkins, like most other self-hosted CI/CD tools resulted in:
- Accumulation/tendency to create vast number of jobs
- Hard and costly maintenance
- Heavy reliance on UI
- Lack of powerful ways to specify conditional logic
Features of Pipeline as Code
Pipelines are implemented as code and typically checked into source control, serving as a single source of truth enabling the team members to edit, review, and iterate upon their pipeline.
Pipelines can optionally stop and wait for human input or approval before continuing the Pipeline run.
-
Pipelines support complex real-world requirements
- Conditional executions
- Chaining jobs
- Linear/Complex flows
The Pipeline plugin supports custom extensions to its DSL and multiple options for integration with other plugins.
Pipeline Autocompletion in IntelliJ
To enable code completion follow below steps:
- Download Pipeline GDSL (http://(yourjenkinsurl)/job/(yourpipelinejob)/pipeline-syntax/gdsl) from your jenkins.
- Add Groovy SDK support to Intellij.
- Place the GDSL file inside
src
directory of your project and mark thesrc
folder asSources Root
. - Open the GDSL file. Now, IntelliJ will show a message
DSL descriptor file has been changed and isn't currently executed.
. ClickActivate
. - Now create your
.groovy
jenkins file and write the code, auto completion will work.
Snippet Generator
You can also generate snippets of code for the pipeline steps using the Snippet Generator
feature available in Jenkins (http://(yourjenkinsurl)/job/(yourpipelinejob)/pipeline-syntax/) which you can then make use of in your pipeline.
Replay
Replay feature allows you to test your pipeline code without having to commit the changes to your Repo. Once you have tested the code you can then push your changes.
Jenkins Declarative Pipeline Example
References
Posted on May 12, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.