Scripted Pipeline unique credential variables per environment

15 views
Skip to first unread message

Mike Zupan

unread,
Sep 21, 2017, 10:36:24 AM9/21/17
to Jenkins Users
So I'm trying to use withCredentials() with unique variables and looking for the best way. 

I have the following password that is unique per region which we call clients

client1 = foo
client2 = bar
client3 = baz

So i have a script that might look like

sh "./deploy -password <unique PW here from above>"

For one region its fine

withCredentials([
        string(credentialsId: 'pw', variable: 'PW'),
]) {
       sh "./deploy -password ${PW}"
}

We have a env that gets passed in like ${env.REGION}

Anyone have a good way with jenkins credentials to lookup a unique PW per region that would easily work for a scripted pipeline. 

Robert Hales

unread,
Sep 21, 2017, 11:28:34 PM9/21/17
to Jenkins Users
I don't have time to build a test of this at the moment, but I am pretty sure you could build your credentials ID in code, based off of your ${env.REGION}, and pass that to the withCredentials like this: 

withCredentials([
    string(credentialsId: "$REGION_CRED", variable: 'PW').
]} { ... }
Reply all
Reply to author
Forward
0 new messages