-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improvement: Add Examples To sh Step [JENKINS-65396] #154
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First comments.
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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More comments for consideration
</pre> | ||
</p> | ||
<b>Escaping script content from groovy interpolation </b>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a mix of scripted and declarative is most helpful to readers, with preference to use declarative when we can
AssemblyInfoGlobal/AssemblyInfoGlobal.cs -r | ||
""")</code> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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