Jenkins: Can comments be added to a Jenkinsfile?
The Jenkinsfile is written in groovy which uses the Java (and C) form of comments:
/* this
is a
multi-line comment */
// this is a single line comment
You can use block (/***/) or single line comment (//) for each line. You should use "#" in sh command.
Block comment
/*
post {
success {
mail to: "[email protected]",
subject:"SUCCESS: ${currentBuild.fullDisplayName}",
body: "Yay, we passed."
}
failure {
mail to: "[email protected]",
subject:"FAILURE: ${currentBuild.fullDisplayName}",
body: "Boo, we failed."
}
}
*/
Single Line
// post {
// success {
// mail to: "[email protected]",
// subject:"SUCCESS: ${currentBuild.fullDisplayName}",
// body: "Yay, we passed."
// }
// failure {
// mail to: "[email protected]",
// subject:"FAILURE: ${currentBuild.fullDisplayName}",
// body: "Boo, we failed."
// }
// }
Comment in 'sh' command
stage('Unit Test') {
steps {
ansiColor('xterm'){
sh '''
npm test
# this is a comment in sh
'''
}
}
}
The official Jenkins documentation only mentions single line commands like the following:
// Declarative //
and (see)
pipeline {
/* insert Declarative Pipeline here */
}
The syntax of the Jenkinsfile is based on Groovy so it is also possible to use groovy syntax for comments. Quote:
/* a standalone multiline comment
spanning two lines */
println "hello" /* a multiline comment starting
at the end of a statement */
println 1 /* one */ + 2 /* two */
or
/**
* such a nice comment
*/