Jenkins with Pipelines

Reading Time: 3 minutes

Jenkins is a self-contained, open-source automation server which can be used to automate all sorts of tasks related to building, testing, and delivering or deploying software. It is a Continuous Integration (CI) server or tool which is written in Java. 

Continuous Integration (CI) is a development practice that requires developers to integrate code into a shared repository several times a day. It is a process of running your tests on a non-developer (say testers) machine automatically when someone pushes new code into the source repository. The below diagram shows the CI workflow

Steps to run Jenkins on your local system 

  1. Download
  2. Open up a terminal in the download directory.
  3. Run java -jar jenkins.war –httpPort=8080.
  4. Browse to http://localhost:8080.
  5. Follow the instructions to complete the installation

Jenkins pipeline

Jenkins Pipeline (or simply “Pipeline”) is a suite of plugins which supports implementing and integrating continuous delivery pipelines into Jenkins.

A continuous delivery pipeline is an automated expression of your process for getting the software from version control right through to your users and customers.

It provides an extensible set of tools for modeling simple-to-complex delivery pipelines “as code”. The definition of a Pipeline is typically written into a text file (called a Jenkinsfile ) which in turn is checked into a project’s source control repository

Two ways of creating pipeline are:-

   1)   Declarative pipeline syntax

   2)  Scripted pipeline syntax

In this blog, we are going to use  Declarative so before starting some basic syntax

Declarative Pipeline is a relatively recent addition to Jenkins Pipeline which presents a more simplified and opinionated syntax on top of the Pipeline sub-systems.

All valid Declarative Pipelines must be enclosed within a pipeline block, for example

pipeline {
    /* insert Declarative Pipeline here */


The agent section specifies where the entire Pipeline, or a specific stage, will execute in the Jenkins environment depending on where the agent section is placed

any :

Execute the Pipeline, or stage, on any available agent. For example agent any

none :

Applied at the root of the pipeline, it indicates that there is no global agent  for the entire pipeline & each stage must specify its own agent

label :

Execute the pipeline/stage on labeled agent


Uses Docker container as an execution environment for the pipeline or a specific stage

pipeline {
   agent any

   stages {

       stage('Compile') {
           steps {
               echo "Compiling..."
               sh "sbt compile"

       stage('Test') {
           steps {
               echo "Testing..."
               sh "sbt test"

       stage('Package') {
           steps {
               echo "Packaging..."
               sh "sbt package"
   post {
       always {
           mail bcc: '', body: 'Please check the build finished', cc: '', from: '', replyTo: '', subject:     ' demo', to: ''  

Steps to create a Jenkins file

1) Create a new project 

 2) Selecting pipeline Script

Select pipeline script as SCM and put the Jenkins file in the root directory of your project and also add you git repository save those changes

  3)    Build and check status 




1 thought on “Jenkins with Pipelines3 min read

Leave a Reply

Knoldus Pune Careers - Hiring Freshers

Get a head start on your career at Knoldus. Join us!