Show List

Creating Jenkins Pipeline

A Jenkins pipeline is a way to automate the software delivery process in Jenkins. It defines the entire process as a series of stages and steps that are executed in a specific order. Pipelines provide a visual representation of the build process and allow you to easily track the status of your builds.

Here's an example of how to create a Jenkins pipeline:

  1. Install the "Pipeline" plugin: To use pipelines in Jenkins, you need to install the "Pipeline" plugin. You can install plugins from the "Manage Plugins" page in the Jenkins web interface.

  2. Create a new pipeline: To create a new pipeline, go to the Jenkins home page and click on the "New Item" link. Choose the "Pipeline" item type and give it a name.

  3. Define the pipeline script: In the job configuration, you need to define the pipeline script that will be executed by Jenkins. The pipeline script is written in Groovy and defines the stages and steps of the build process.


Demo

Click on "Create a Job" button
Enter the name and select "Pipeline"
Enter the pipeline script as below. Refer to site "https://opensource.triology.de/jenkins/pipeline-syntax/" for generating the script.
pipeline {
    agent any

    stages {
        stage('Clean Up') {
            steps {
                deleteDir()
            }
        }
        stage('Clone Repo') {
            steps {
                sh 'git clone https://github.com/it-code-lab/Spring-Boot-Rest-Service.git'
            }
        }
         stage('Build') {
            steps {
                dir("Spring-Boot-Rest-Service"){
                    sh 'mvn clean install'
                }
            }
        }
         stage('Test') {
            steps {
                dir("Spring-Boot-Rest-Service"){
                    sh 'mvn test'
                }
            }
        }
    }
}
Click on "Save" and then run the build. Please note that the pipeline is running some maven commands so we need to have maven installed on the container. The steps can be followed from Earlier Chapter if not already installed. 

    Leave a Comment


  • captcha text