Jenkins 2.0 Pipelines

Jero

First of all, What is Jenkins?

Jenkins is an open source continuous integration (CI) and continuous delivery (CD) tool written in Java.

It’s automation server used to build and deliver software project. Jenkins was a forked from another project called Hudson, after a dispute with Oracle. A major benefit of using jenkins is that it has a lot of plugins available.

Job DSL (older) vs Pipelines

  • They both have the capability to write all your CI/CD in code.
  • The difference is in implementation in Jenkins
  • Jenkins Job DSL creates new jobs, based on the code you write.
  • The Jenkins pipelines is a job type, you can create a Jenkins pipeline job that will handle the build/test/deployment of one project.
  • The Jenkins pipelines is a specific job type, that can be created using the Jenkins UI or the Jenkins job DSLs.
  • You could use Jenkins Job DSLs to create a new Pipeline Jobs (as we mentioned before).
  • You could use an Organization Folder, which is a feature of Jenkins Pipelines, to detect the project repositories, removing the need to add new jobs.

Then Jenkins Pipeline

Jenkins Pipeline allow you to write the Jenkins build steps in code.

  • Build steps, allow you to write, build (compile), test and deploy your code.
  • Code, means you can put this code in version control.

Jenkins Pipelines Example

  • A text file that stores the pipeline as code.
  • It can be checked into a SCM on your local system.
  • Enables the developers to access, edit and check the code at all times.
  • It is written using the Groovy DSL

Scripted Pipeline

  • Traditional way of writting the code.
  • Stricted groovy syntax
  • Code is writing on the Jenkins UI instance
  • The code is defined within a `node` block:

The important part here is named “Stages”, in which each stage like we se above (Preparation, Build, Results), conceptually are like steps, and that steps are used by others plugins in Jenkins later on the visualize the stages of a Job.

Declarative Pipelines

  • Recent feature
  • Simpler groovy syntax
  • Code is written locally in a file and is checked into a Souce control managment.
  • The code is defined within a `pipeline` block.
  • When you can choose to write the pipeline in Jenkins DSL (under the hood the Jenkins DSL is interpreted by Groovy).

The following script is a example of a Declarative Pipeline:

The first parameter agent it could be defined for entire pipeline or just a specific stage. That instructs to Jenkins to allocate an executor for the builds.

Well, move on to create inside Jenkins a scripting pipeline step by step

Then you need to choose between Declarative Pipeline (from your Git) or Pipeline script:

If you choose Pipeline Script:

Note: In the line 11 we are calling an already existing Declarative pipeline (will see how to create them).

If you choose Declarative Pipeline (Pipeline script from SCM)

Also, for declarative pipeline you will need to define you Jenkins file (some tabs but need scroll down), and then click Save button.

In that way once you create them, you will see in your Jenkins list. To see a full list of the full here is the file.


Please give me your thoughts about this short article, I love to share ideas, learn from others and I hope this article may be helpful for someone out there!

Also you can following me on Twitter!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade