4

I am trying to create a Jenkins pipeline where I need to execute multiline shell commands.

stage ('Test'){
name="myserver"
sh '''
    "ssh -o StrictHostKeyChecking=no ${myserver} 'rm -rf temp && mkdir -p temp && mkdir -p real'"
'''

}

But it is always returning error as "command not found". If I run the same with

sh "ssh -o StrictHostKeyChecking=no ${myserver} 'rm -rf temp && mkdir -p temp && mkdir -p real' "

Is there a different way to access variable in multiline shell?

Sreehari
  • 1,328
  • 11
  • 29
  • Possible duplicate of [What's the difference of strings within single or double quotes in groovy?](https://stackoverflow.com/questions/6761498/whats-the-difference-of-strings-within-single-or-double-quotes-in-groovy) – mkobit Jun 18 '18 at 13:34

1 Answers1

12

You need to use """ like this:

sh """
    "ssh -o StrictHostKeyChecking=no ${myserver} 'rm -rf temp && mkdir -p temp && mkdir -p real'"
"""
Tomas Bjerre
  • 3,270
  • 22
  • 27