Georg Heiler
Georg Heiler

Reputation: 17676

Jenkins workflow pass variable to shell script

How can I pass a variable e.g. buildNumber

sh 'gulp sometask --someOption="attribute=${env.BUILD_NUMBER}"'

to the sh command using Jenkins workflow / pipeline? My example unfortunately only yields a bad substitution error.

Upvotes: 0

Views: 1651

Answers (3)

Mateusz Wocka
Mateusz Wocka

Reputation: 31

Could you try this command:

sh """gulp sometask --someOption='attribute=${env.BUILD_NUMBER}'"""

Upvotes: 1

ansib
ansib

Reputation: 524

could you please try this command here:

sh "gulp sometask --someOption='attribute=${env.BUILD_NUMBER}'"

The quotation marks are exchanged. I think the reason is, that you can templating with double quotes (using GString), which doesn't work with single quotes (using a plain String) in groovy.

for more information see the Groovy Documentation

Upvotes: 4

Bimal
Bimal

Reputation: 1243

Did you try

sh 'gulp sometask --someOption="attribute=${BUILD_NUMBER}"'

Upvotes: -1

Related Questions