lundi 18 février 2019

Variable value inside Jenkins Pipeline script sh command

I am trying to write a Jenkins script, and I am having trouble resolving one command. There is this if statement which checks for the existence of a remote directory and if it is available, it will provide permissions for the same and if not it will return failure. The problem is that, a part of the directory path is derived using a variable and that variable is being referenced as $variable_name. The problem I am facing is, that variable is either coming as a complete string or it is getting an empty value inside the if command. When we check the value outside using echo, it is returning the correct value. The following is a piece of my code:

def myversion ="${params.AppzillonVersion}"
pipeline {
  agent { label 'example' }
    stages {
      stage('Testing Stage') {
         steps {
            script { 
                sh "echo '${myversion}'"
                sh '''if sshpass -p p@ssw0rd ssh superuser@192.168.1.6 '[ -d "/Appzillon/Appzillon-${myversion}/Mac" ]'; then 
sshpass -p p@ssw0rd ssh superuser@192.168.1.6 "echo p@ssw0rd | sudo -S chmod -R 777 /Appzillon/Appzillon-${myversion}/Mac"
else
    echo "failure"
fi'''
                  }
                }
             }
          }
      }

And the console output is

echo test
test
[Pipeline] sh
+ sshpass -p remote_user_password ssh remote_user_name@remote_user_address [ -d "some_path_here-${myversion}/Mac" ]
+ echo failure
failure

From the console output, I can see the ${myversion} coming as it is rather than the passed parameter which is 'test' Any help is appreciated.

Aucun commentaire:

Enregistrer un commentaire