diff --git a/src/main/resources/org/jenkinsci/plugins/workflow/steps/durable_task/ShellStep/help-script.html b/src/main/resources/org/jenkinsci/plugins/workflow/steps/durable_task/ShellStep/help-script.html index 908c2653..d75fc8f1 100644 --- a/src/main/resources/org/jenkinsci/plugins/workflow/steps/durable_task/ShellStep/help-script.html +++ b/src/main/resources/org/jenkinsci/plugins/workflow/steps/durable_task/ShellStep/help-script.html @@ -9,4 +9,46 @@ Otherwise the system default shell will be run, using the -xe flags (you can specify set +e and/or set +x to disable those).

- \ No newline at end of file +

A few examples of usage include:

+ + Creating an output folder +

sh 'mkdir -p output'

+ + Reporting the current directory of the Pipeline step. +

sh 'pwd'

+ + Making HTTP requests with curl (scripted Pipeline) +

+    def payload='payload to send'
+    def slackURL='https://example.slack.com/archives/CCQU3EHYP'
+    sh "curl -X POST --data-urlencode \"payload=${payload}\" ${slackURL}"
+    

+ + Running tests in the same workspace that the project was built +

sh 'mvn test'

+ Using multi-line syntax to run several lines of script: +

+

+    sh '''
+    echo "This is a first line of script"
+    # This is a script comment
+    echo "This is a second line"
+    '''
+        
+

+ Escaping script content from groovy interpolation > +

The triple-double-quote (""") string literal syntax allows for variable/expression substitution (interpolation), so the backslash (\) is interpreted as a special character "escape".

+

Since the first open parentheses is not such a special character, Groovy compilation fails. If your intent is to have literal backslashes in the resulting string, you need to escape the backslashes. That is, use a double-backslash (\\) to substitute for one literal backslash

+

sh (""" + sed "s/(AssemblyInformationalVersion\\(\\")(.*)(\\")/\\1${productVersion}\\3/g" + AssemblyInfoGlobal/AssemblyInfoGlobal.cs -r + """) +

+ + Adding shell script as part of Groovy interpolation > +

For double quoted string, Groovy will do interpolation on the string firstly.

+

Because the variables are runtime variables of the shell, rather than the variables of Groovy runtime. Groovy can't find the responding value from Groovy variable stack to replace the variables during interpolation.

+

So you need to escape all $ if you use double quotes or simply use single quotes which does not support interpolation

+

sh(returnStdout: true, script: "cd \$it; PLAN=\$(terragrunt plan --terragrunt-source-update | landscape); + echo \$PLAN; CHANGES=\$(echo \$PLAN | tail -2); echo \$CHANGES"

+