• Home
  • About
    • Harshad Ranganathan photo

      Harshad Ranganathan

      Multi-Cloud ☁ | Kubernetes Certified

    • Learn More
    • Email
    • LinkedIn
    • Github
    • StackOverflow
  • Posts
    • All Posts
    • All Tags
  • Projects

Jenkins Pipeline as Code

12 May 2018

Reading time ~1 minute

Table Of Contents

  • Jenkins Pipeline
  • Need for Jenkins Pipeline as Code
  • Features of Pipeline as Code
  • Pipeline Autocompletion in IntelliJ
  • Snippet Generator
  • Replay
  • Jenkins Declarative Pipeline Example
  • References

Jenkins Pipeline

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:

  1. Download Pipeline GDSL (http://(yourjenkinsurl)/job/(yourpipelinejob)/pipeline-syntax/gdsl) from your jenkins.
  2. Add Groovy SDK support to Intellij.
  3. Place the GDSL file inside src directory of your project and mark the src folder as Sources Root.
  4. Open the GDSL file. Now, IntelliJ will show a message DSL descriptor file has been changed and isn't currently executed.. Click Activate.
  5. 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.

Like the content ? 

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

Like the content ? 

References

https://www.cloudbees.com/blog/need-jenkins-pipeline



jenkinspipeline as codejenkinsfilecontinuos delivery with pipelinepipeline gdslpipeline replaysnippet generatorjenkins pipeline tutorial for beginnersjenkins pipeline pluginjenkins pipeline build jobjenkins pipeline github Share Tweet +1