Pipeline

Jenkins Pipeline is a suite of plugins which supports implementing and integrating continuous delivery pipelines into Jenkins.

Defining your Pipeline

The definition of a Jenkins Pipeline is written into a text file (called a Jenkinsfile) which in turn is committed to a project’s source control repository.

The following sample Pipeline example is equipped with common stages of CI/CD and an additional "Meterian Scan" stage

// Jenkinsfile

pipeline {
    agent any
    options {
        skipStagesAfterUnstable()
    }
    stages {
        stage('Build') {
            steps {
                // Some build steps...
            }
        }
        stage('Test') {
            steps {
                // Run tests...
            }
        }
        stage('Meterian Scan') {
            steps {
                withCredentials([string(credentialsId: 'MeterianApiToken', variable: 'METERIAN_API_TOKEN')]) {
                    sh '''
                        echo Perform Meterian vulnerability scan...
                        docker run --rm -v $(pwd):/workspace -e METERIAN_API_TOKEN=$METERIAN_API_TOKEN meterian/cli
                    '''
                }
            }
        }
        stage("Deploy") {
            steps {
                // Deployment...
            }
        }
    }
}

Note: the above "Meterian Scan" stage uses the withCredentials plugin for credentials binding and requires you to set your API token within Jenkins's credentials with an ID of choice.

Once your Pipeline is placed within the repository with the codebase you wish to scan, all that is left to do is configuring Jenkins for its execution.

Pipeline configuration in Jenkins

1) In the Jenkins homepage, click on New Item on the top left dashboard

2) Enter an item name, from the relative wizard, specifying the name of your new Pipeline project. Then click on Pipeline and OK at the end of the page to confirm and open the Pipeline configuration page.

3) In the Pipeline configuration page, click the Pipeline tab at the top of the page to scroll down to the Pipeline section. Here select Pipeline script from SCM from the Definition field and fill the subsequent information about your SCM of choice where your repository containing your Jenkinsfileis hosted

4) Once done configuring Save your work

Now when you update the designated repository, a new build is triggered, as long as the Pipeline is configured with an SCM polling trigger. Alternatively you can manually trigger it by clicking Build Now in your newly created Pipeline project menu.

Last updated