There are a couple different things to notice here:

   1. Double quotes in Groovy is string interpolation 
   
<http://docs.groovy-lang.org/latest/html/documentation/index.html#_string_interpolation>
      - Your *sh "cp $SETTINGS_LOCATION ./settings.xml"* is using string 
      interpolation and *$SETTINGS_LOCATION *is being evaluated in the 
      script, but that variable is not present
   2. *withCredentials* binds to an environment variable 
   
<https://jenkins.io/doc/pipeline/steps/credentials-binding/#withcredentials-bind-credentials-to-variables>.
 
   So, *SETTINGS_LOCATION* *should* be available for execution on the 
   allocated nodes

There are a few ways I believe you could fix this:

   1. Use the *env* global variable (like previously mentioned) to 
   substitute in the value through the Groovy which will retrieve the 
   previously set environment variable by *withCredential*
      - 
*sh "cp ${env.SETTINGS_LOCATION} ./settings.xml" *
   2. Use single quotes to delay the evaluation of the $*SETTINGS_LOCATION 
*until 
   the script executes on the node and uses environment variable substituion 
   (I believe this would work, haven't tested it)
      - *sh 'cp $SETTINGS_LOCATION ./settings.xml'*
      
I believe the second example will not output the value to the logs (which 
may be important if you do other credentials substitutions, like 
UsernamePasswordMultiBinding)

On Friday, June 10, 2016 at 7:56:42 AM UTC-5, Michael Irwin wrote:
>
> Versions (current for each)...
> - Jenkins - 2.8
> - Credentials Plugin - 2.0.7
> - Credentials Binding Plugin - 1.7
> - Pipeline: Multibranch - 2.6
> (let me know if you need any others)
>
> - Working in a multibranch project
> - Created a "Secret File" credential in the Global scope (just for 
> testing) with id "settings-file".  
> - Jenkinsfile has:
>
> node {
>   ...
>   withCredentials([$class: 'FileBinding', credentialsId: 'settings-file', 
> variable: 'SETTINGS_LOCATION']) {
>     sh "cp $SETTINGS_LOCATION ./settings.xml"
>   }
>   ...
> }
>
> When it runs, get hit with...
>
> groovy.lang.MissingPropertyException: No such property: SETTINGS_LOCATION for 
> class: groovy.lang.Binding
>
>
> Oddly, when I open the "Pipeline Syntax" at the project, I'm able to produce 
> a Groovy snippet for the credential.  But, if I open the "Pipeline Syntax" at 
> the branch level (within the project folder), there are no credentials 
> available for me to select in the snippet generator.  So, it seems that the 
> folder isn't getting the same visibility to the credential (even though it 
> was defined globally).
>
> Any pointers?
>
> --
> Michael Irwin
>
>

-- 
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/d575ffc9-b280-457a-90bc-ab01271fc3d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to