What is use of sh ''' <command > ''' - three ticks - in a Jenkinsfile? What is use of sh ''' <command > ''' - three ticks - in a Jenkinsfile? jenkins jenkins

What is use of sh ''' <command > ''' - three ticks - in a Jenkinsfile?


This has nothing at all to do with bash (in which triple-quotes have no special meaning at all), and everything to do with Groovy (the separate, non-bash interpreter that parses Jenkinsfiles).

In Groovy, but not in bash, strings must use triple-quotes to span multiple lines.

In the context of a sh directive in a Jenkinsfile, the content of your triple-quoted string is passed to a shell as a script to execute; however, the syntax is parsed by Groovy, so it's only Groovy that cares about the quotes themselves (as opposed to the quoted content).


Can you give more idea about what kind of command is it, is it a unix command or some script ?

The single quote and its variation like '''(3 ticks) as mentioned in question skip the variable expansion, and it could used to show what is being executed.

echo '''Updating JAVA_HOME variable :export $JAVA_HOME="$NEW_JAVA_HOME" '''

However in your question, a command (some string) is enclosed between 3 ticks marks and sh tries to execute this command or script. One such example below

$ echo "echo hello" > /tmp/tesh.sh$ sh '''/tmp/test.sh'''hello