Black Friday 2025 – NPI EA (cat = Baeldung on Ops)
announcement - icon

Yes, we're now running our Black Friday Sale. All Access and Pro are 33% off until 2nd December, 2025:

>> EXPLORE ACCESS NOW

Partner – Orkes – NPI EA (cat=Kubernetes)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

1. Overview

In this tutorial, we’ll see how we can use comments in Jenkinsfile. We will cover different types of comments and their syntax.

2. Comments in a Jenkinsfile

The syntax of Jenkinsfile is based on Groovy, so it’s possible to use Groovy syntax for comments. Let’s take a simple example of Pipeline Linter and try to comment it out.

2.1. Single-Line Comments

Single-line comments in Jenkinsfile are the same as we see in popular languages like Java, C++, and C#.

They start with two forward slashes (//). Any text between // and the end of the line is commented and ignored in Jenkinsfile.

Let’s use single-line comments to comment out a basic pipeline definition:

//pipeline {
//    agent any
//    stages {
//        stage('Initialize') {
//            steps {
//                echo 'Hello World'
//            }
//        }
//    }
//}

2.2. Block Comments

Block comments in Jenkinsfile are used to comment out a block of code. Again, the pattern is similar to Java and C++.

A block comment starts with a forward-slash followed by an asterisk (/*) and ends with an asterisk followed by a forward-slash (*/). The beginning (/*) and ending (*/) characters will be added to the appropriate places to mark the selected block as a comment.

In this example, we’ll use block comments to comment out the pipeline definition:

/*
pipeline {
    agent any
    stages {
        stage('Initialize') {
            steps {
                echo 'Placeholder.'
            }
        }
    }
}
*/

2.3. Comments in Shell Script

While inside of a shell (sh) section, we’ll be using the shell comment character, hash (#), for commenting:

pipeline {
    agent any
    stages {
        stage('Initialize') {
            steps {
                sh '''
                cd myFolder
                # This is a comment in sh & I am changing the directory to myFolder
                '''
            }
        }
    }
}

3. Conclusion

In this short article, we covered different types of comments in a Jenkinsfile. First, we looked at single-line comments. Next, we saw how to use block comments. Finally, we showed how to add comments within a shell section of a Jenkinsfile.