Issue
I am trying to resolve a parameter inside a windows path, so can we do that.
def Job_Name=params.Job_Name
pipeline {
agent none
options {
skipDefaultCheckout()
}
stages {
stage("Export_Package"){
agent {
label 'xxxxx'
}
steps{
bat 'E:\\sashome\\SASPlatformObjectFramework\\9.4\\ExportPackage -user "xxxxx" -password "xxxxxx" -host "xxxxxxx.com" -port "1234" -package "E:\\sasconfig\\Lev1\\SASApp\\SASEnvironment\\SASCode\\Jobs\\Devops_EportJobs\\"${Job_Name}".spk" -objects "/Shared Data/Jenkins" -subprop "${Job_Name}".subprop'
}
}
}
}
Can we call "${Job_Name}" like this inside the path?? If not, can someone please let me know how to accomplish the same. I just want to pass the Job_Name inside the path, so that I don't have to hard code the job_Name.spk and can keep it dynamic. Whatever Job_name I will pass on the Parameter it should pick that and resolve the same before .spk
Please help me if possible.
Solution
Read groovy string basics: https://groovy-lang.org/syntax.html
Basically, you're wrapping your argument with single quotes when you should be using double quotes. Then when using double quotes, escape all the double quotes within the argument itself:
bat "E:\\sashome\\SASPlatformObjectFramework\\9.4\\ExportPackage -user \"xxxxx\" -password \"xxxxxx\" -host \"xxxxxxx.com\" -port \"1234\" -package \"E:\\sasconfig\\Lev1\\SASApp\\SASEnvironment\\SASCode\\Jobs\\Devops_EportJobs\\\"${Job_Name}\".spk\" -objects \"/Shared Data/Jenkins\" -subprop \"${Job_Name}\".subprop"
From reading the comment, it seems this is what you are looking for (removed literal quotes around Job_Name variable):
bat "E:\\sashome\\SASPlatformObjectFramework\\9.4\\ExportPackage -user \"xxxxx\" -password \"xxxxxx\" -host \"xxxxxxx.com\" -port \"1234\" -package \"E:\\sasconfig\\Lev1\\SASApp\\SASEnvironment\\SASCode\\Jobs\\Devops_EportJobs\\${Job_Name}.spk\" -objects \"/Shared Data/Jenkins\" -subprop ${Job_Name}.subprop"
Answered By - Perplexabot
Answer Checked By - Terry (JavaFixing Volunteer)