brian661
brian661

Reputation: 548

Jenkins groovy : set environment variable between quote

I am trying to set a environment variable to a http request header. For example

""" --header 'Authorization: "${auth}"' """

But probaly due to the quote '...', the ${auth} is not correctly set.

A simple example:

job(jobName) {
    wrappers {
        environmentVariables {
            env('auth', 'something I want to set')
        }
    }
    steps {
        shell(''' echo "${auth}" ''')
    }
}

my test:

shell(''' echo "${auth}" ''') --> correctly echo
shell(''' echo '"${auth}"' ''') --> not echo correctly
shell(""" echo '"${auth}"' """) --> not echo correctly

Upvotes: 2

Views: 1678

Answers (1)

Sudharsan Sivasankaran
Sudharsan Sivasankaran

Reputation: 5887

per-character escaping: \"

~ auth="test"
~ echo "\"${auth}\""
"test"

concatenation: '"' ${auth} '"'

~ echo '"'${auth}'"'
"test"

Upvotes: 1

Related Questions