I'm trying to set up a string parameter which will reference a variable 
which will be created within the pipeline.  For instance, when building a 
parameterized build, the user enters a file path in this 
format: /srv/jboss/server/${MAL}/log/

Where MAL is assigned via the pipeline and then I try to ls -ltr the fully 
qualified path after MAL has been expanded.  However I'm not getting it to 
expand; wondering what I'm doing wrong.

node {
MALarray = params.multi.split(',')

MALarray.each { MAL ->
         
if (MAL in ['care''] )  {
            servers = ['xx.xx.xx.xx','xx.xx.xx.xx']
        }

def soc_remote = [:]
soc_remote.name = "${MAL} SOC"
soc_remote.allowAnyHosts = true

withCredentials([usernamePassword(credentialsId: 'Credentials', 
usernameVariable: 'USER_ID', passwordVariable: 'USER_PASSWORD')]) {
soc_remote.user = USER_ID
soc_remote.password = USER_PASSWORD
servers.each { server ->
            soc_remote.host = server
stage("Run script on ${server}") {
    try {
    echo("MAL is ${MAL}")
    sshCommand remote: soc_remote, command: "ls -ltr ${filepath}"
    } catch (err) {
                          echo "something failed"
                          echo "${err}"
                          }
}
}
        }
}
} 

Console output:
*11:59:34* MAL is care 
*11:59:34* [Pipeline] sshCommand 
<https://abaapvsc01amcba.tdbfg.com:9443/job/CraigTest/job/variable%20inside%20variable/2/console#>
 
*11:59:34* Executing command on care SOC[xx.xx.xx.xx]: ls -ltr 
/srv/jboss/server/${MAL}/log/ sudo: false 
*11:59:35* ls: cannot access /srv/jboss/server//log/: No such file or 
directory 
*11:59:35* Failed command care SOC#1002 with status 2: ls -ltr 
/srv/jboss/server/${MAL}/log/  

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/11fcfc93-6e5c-4f50-a637-964e06bf66een%40googlegroups.com.

Reply via email to