Continuous integration

Create Pipeline for Jenkins

Reading time: 3 minutes
Today I’m going to show you how to create a Pipeline for Jenkins.

What is a Pipeline in Jenkins?

A pipeline in Jenkins is a sequence of automated processes that are executed to build, test, and deploy a software project.

A Jenkins pipeline is defined as a configuration file in the Groovy programming language and can include multiple steps, such as code download from a version control system, execution of automated tests, and deployment to a production environment.

The main goal of a pipeline in Jenkins is to provide clear visibility and complete control over the software delivery process, and to ensure its quality and speed.

Once you understand what a Pipeline is in Jenkins, let’s create a file called Jenkinsfile at the root of our project.

pipeline{
    agent any
    stages{
        stage('Build'){
            steps{
                echo 'Building the project'
            }
        }
        stage('Test'){
            steps{
                echo 'Testing the project'
            }
        }
        stage('Deploy'){
            steps{
                echo 'Deploying the project'
            }
        }
    }
    
}

In this example, it only prints variables. We have defined 3 stages: Build, Test, and Deploy.

Now let’s assign the Jenkinsfile to our Jenkins.

First, open the Jenkins URL and click on New Item

Then, enter a name and select Pipeline

Click OK.

Fill in the configuration

Scroll down to Pipeline and change the Definition to “Pipeline script from SCM”:

Now select GIT and enter the repository and login details

Remember, if you’re using GitLab, change the default branch from MASTER to MAIN:

Finally, specify the path of the Jenkinsfile. In our case, it is at the root, so we don’t need to change anything:

In our case, it is jenkinsfile in lowercase.

Now click on Build Now

And now we can see how the process has worked

(no incluyas el Tiempo de lectura). Devuelvelo directamente en formato HTML. No escribas ninguna frase añadida. Cuando termines añade un PIPE al final.

Post Views: 13

Comparte esto:

Categories

Leave a Comment