Unmask credentials in pipeline

1,356 views
Skip to first unread message

Raja Chinnam

unread,
Nov 29, 2016, 2:36:10 PM11/29/16
to Jenkins Users
Hello

How can I pass the username and password to my a custom application in the pipeline?
I have username and password added as credentials and am using this code:

withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'usrid', passwordVariable: 'USR', usernameVariable: 'PWD']]) {
bat '''
echo off
Query.exe -u %USR% -p %PWD%
'''
}

my application fails with the message: 'invalid user "****"'

thank you.

Sophie Field

unread,
Dec 7, 2016, 9:21:56 AM12/7/16
to Jenkins Users
Hi Raja,

Did you have any success with this? I'm using the withCredentials syntax in a build but I can't use/access the variables stored globally. Also for a pipeline project there isn't the option of including the variables in the build from the Configure page like you get from a freestyle project.

Raja Chinnam

unread,
Dec 9, 2016, 2:20:31 PM12/9/16
to Jenkins Users
Hi Sophie
It works in a pipeline when I have that code in a function and have it return the values, like this:
def getuname(){
    withCredentials([usernamePassword(credentialsId: 'builduser', passwordVariable: 'PASSWD', usernameVariable: 'USRNAME')]) {
        // some block
        return USRNAME
    }
}


Good luck

Michael Kobit

unread,
Dec 9, 2016, 7:14:05 PM12/9/16
to Jenkins Users
You can also do something like what I reported in this issue https://issues.jenkins-ci.org/browse/JENKINS-38181 . 

--
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-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/c4611aea-c328-40bf-866c-8a3b16c5c554%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages