Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I read Jenkins pipeline variable in multiline shell?

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?

like image 242
Sreehari Avatar asked Sep 01 '25 01:09

Sreehari


1 Answers

You need to use """ like this:

sh """
    "ssh -o StrictHostKeyChecking=no ${myserver} 'rm -rf temp && mkdir -p temp && mkdir -p real'"
"""
like image 51
Tomas Bjerre Avatar answered Sep 02 '25 14:09

Tomas Bjerre