Why Pipelines

Visualise your Continuous Delivery system

Just like an automobile assembly line, pipelines allow you to create and visualize the end-to-end flow of your build, test and delivery system. A good pipeline will show how a change to the software gets delivered to a customer. Jenkins makes it easy to do this using its Groovy DSL to create separate stages for build, test and deployment. Here is an example of a working skeleton pipeline:

pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                echo 'TODO: Build code here'
            }
        }
        stage('Test') {
            steps {
                echo 'TODO: Test code here'
            }
        }
        stage('Deploy') {
            steps {
                echo 'TODO: Deployment code here'
            }
        }
    }
}

 

Creating the Pipeline

Just like in the video tutorial, click New Item to create a new job, only this time choose Pipeline instead of freestyle Project.

pipeline-new

Click OK to continue and scroll down to the bottom of the configuration window. Copy and paste the skeleton pipeline from above into the Script box and press Save.

pipeline-edit

Click Build Now to run your first pipeline! If successful, you should see a Stage View with every stage colored green for passing.

pipeline
Pipeline view of the skeleton example

 

Complex Pipelines

In more complex workflows, you can chain multiple pipelines together to test your software under different conditions or environments. In this example, we have created three pipelines already which have different responsibilities:

  • build-pipeline
  • unit-test-pipeline
  • integration-test-pipeline

The complex pipeline uses the build step to initiate these pipelines and runs the two test pipelines in a parallel step for fast feedback.

pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                build 'build-pipeline'
            }
        }
        stage('Test') {
            steps {
                parallel (
                   'Unit Test' : {
                        build 'unit-test-pipeline'
                    },
                    'Integration Test' : {
                        build 'integration-test-pipeline'
                    }
                )
            }
        }
        stage('Deploy') {
            steps {
                build 'deployment-pipeline'
            }
        }
    }
}

 

Click on Open Blue Ocean to see what the complex pipeline looks like in the newer Jenkins interface.

pipeline2
Blue Ocean view of the multi-pipeline example

 

To learn more about pipelines, see the official documentation for Jenkins Pipelines and pipeline examples.

Read this excellent article describing the power of Jenkins pipelines: Jenkins pipelines and their dirty Secrets.

Next

Jenkins: Git Integration