Improvement: Add Examples To sh Step [JENKINS-65396]#154
Improvement: Add Examples To sh Step [JENKINS-65396]#154Queen-esther01 wants to merge 5 commits intojenkinsci:masterfrom
Conversation
src/main/resources/org/jenkinsci/plugins/workflow/steps/durable_task/ShellStep/help-script.html
Outdated
Show resolved
Hide resolved
| <b>Escaping script content from groovy interpretation </b>> | ||
| <p>The triple-double-quote (""") string literal syntax allows for variable/expression substitution (interpolation), so the backslash (\) is interpreted as a special character "escape".</p> | ||
| <p>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</p> | ||
| <p><code>sh (""" |
There was a problem hiding this comment.
I am not sure that we want to document scripted pipeline, any other opinions for other reviewers ? I would prefer to only have declarative pipeline in help.
There was a problem hiding this comment.
I think this might be helpful to a few people, i specifically added it because of feedback from a user.
There was a problem hiding this comment.
I think a mix of scripted and declarative is most helpful to readers, with preference to use declarative when we can
…e_task/ShellStep/help-script.html Co-authored-by: A. Jard <angelique.jard@gmail.com>
src/main/resources/org/jenkinsci/plugins/workflow/steps/durable_task/ShellStep/help-script.html
Outdated
Show resolved
Hide resolved
src/main/resources/org/jenkinsci/plugins/workflow/steps/durable_task/ShellStep/help-script.html
Outdated
Show resolved
Hide resolved
…e_task/ShellStep/help-script.html Co-authored-by: Mark Waite <mark.earl.waite@gmail.com>
…e_task/ShellStep/help-script.html Co-authored-by: Mark Waite <mark.earl.waite@gmail.com>
MarkEWaite
left a comment
There was a problem hiding this comment.
Possible additional changes
src/main/resources/org/jenkinsci/plugins/workflow/steps/durable_task/ShellStep/help-script.html
Outdated
Show resolved
Hide resolved
src/main/resources/org/jenkinsci/plugins/workflow/steps/durable_task/ShellStep/help-script.html
Outdated
Show resolved
Hide resolved
Co-authored-by: Mark Waite <mark.earl.waite@gmail.com>
MarkEWaite
left a comment
There was a problem hiding this comment.
More comments for consideration
| ''' | ||
| </pre> | ||
| </p> | ||
| <b>Escaping script content from groovy interpolation </b>> |
There was a problem hiding this comment.
Remove extra trailing >
| <b>Escaping script content from groovy interpolation </b>> | |
| <b>Escaping script content from groovy interpolation </b> |
| <b>Escaping script content from groovy interpretation </b>> | ||
| <p>The triple-double-quote (""") string literal syntax allows for variable/expression substitution (interpolation), so the backslash (\) is interpreted as a special character "escape".</p> | ||
| <p>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</p> | ||
| <p><code>sh (""" |
There was a problem hiding this comment.
I think a mix of scripted and declarative is most helpful to readers, with preference to use declarative when we can
| sed "s/(AssemblyInformationalVersion\\(\\")(.*)(\\")/\\1${productVersion}\\3/g" | ||
| AssemblyInfoGlobal/AssemblyInfoGlobal.cs -r | ||
| """)</code> |
There was a problem hiding this comment.
Alternate example that shows a multi-line shell script using triple double quotes.
| sed "s/(AssemblyInformationalVersion\\(\\")(.*)(\\")/\\1${productVersion}\\3/g" | |
| AssemblyInfoGlobal/AssemblyInfoGlobal.cs -r | |
| """)</code> | |
| sh """ | |
| echo 'This text is single quoted' | |
| echo "This text is double quoted" | |
| echo "This text doesn't contain a double quote" | |
| echo This text doesn\\'t include an embedded double quote, it has an embedded single quote | |
| """ | |
| </code> |
| <p>The triple-double-quote (""") string literal syntax allows for variable/expression substitution (interpolation), so the backslash (\) is interpreted as a special character "escape".</p> | ||
| <p>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</p> |
There was a problem hiding this comment.
May want to use a simpler example.
Alternate example attached for you to consider.
This pull request contains example additions to the sh step. I added a few use cases in which shell script can be used in pipelines and escaped or recognized in groovy interpolation.
Issue link on Jira https://issues.jenkins.io/browse/JENKINS-65396?filter=-1
@MarkEWaite