Home > database >  How can I use a variable in a Jenkinsfile inside sshagent?
How can I use a variable in a Jenkinsfile inside sshagent?

Time:07-08

There are many threads about similiar problems on stackoverflow but they couldn't help me with my specific case:

node{
  def USER = "user"
  def ADRESS= "adress"
  def ARGUMENT= "argument"

  stage('test'){
    sshagent(['123123']) {
      sh 'ssh ${USER}@${ADRESS} "command ${ARGUMENT} && command"'
    }
  }
}

In the console output ${USER} and ${ADRESS} will resolve to an empty string but ${ARGUMENT} will resolve to "argument". How do I have to format these placeholders that they work? I have tried everything I could find but nothing seems to work.

CodePudding user response:

As @NoamHelmer pointed out:

sh "ssh ${USER}@${ADRESS} \""command ${ARGUMENT} && command\""

works.

  • Related