String Interpolation In Jenkins logo jenkins

String Interpolation In Jenkins

Jenkins Pipeline uses rules identical to Groovy for string interpolation. Groovy’s String interpolation support can be confusing to many newcomers to the language. While Groovy supports declaring a string with either single quotes, or double quotes, for example:

def singlyQuoted = 'Hello'
def doublyQuoted = "World"

Only the latter string will support the dollar-sign ($) based string interpolation, for example:

def username = 'Jenkins'
echo 'Hello Mr. ${username}'
echo "I said, Hello Mr. ${username}"

This would result in:

Hello Mr. ${username}
I said, Hello Mr. Jenkins

Hence, to use $ sign interpolation in the Jenkins pipeline we must use a double quote String even though, it supports a single quote string.

Notify of
Inline Feedbacks
View all comments