Jenkins pipeline credentials single vs double quotes interpolation

Viewed 822

I'm getting this Warning: A secret was passed to "httpRequest" using Groovy String interpolation, which is insecure using the first example here. I made this keyvar = credentials('key_id') as an environmental variable and put it in something like this

 def response = httpRequest url: "https://url...", 
           customHeaders: [[name: 'Authorization', value: "${keyvar}"]]...

Which works but is not how it should be properly done as described in this documentation, so following that I tried what it suggested here, using single quotes and no bracket.

 def response = httpRequest url: "https://url...", 
           customHeaders: [[name: 'Authorization', value: '$keyvar']]...

This solves the first error but now I get Response Code: HTTP/1.1 401 Unauthorized which to me, means that interpolation isn't working within the single quotes as the documentation describes.

2 Answers

Instead of httpRequest method, I have the aliOssUpload method. It doesn’t work by passing the argument directly to the argument without recasting as a string.

The interpolation warning can be resolved by escaping the $\keyvar

Related