jenkins - In a Jenkinsfile, what are all the types that can be used with `withCredentials` - Stack Overflow

admin2025-04-16  5

In a jenkinsfile, the "Credentials Binding" plugin can be used with withCredentials.

Example:

withCredentials([usernamePassword(etc)]) { ... }

What are all the credential types that can be used with withCredentials, what are their keywords and parameters, and how do they appear in the Jenkins server "credentials" GUI?

In a jenkinsfile, the "Credentials Binding" plugin can be used with withCredentials.

Example:

withCredentials([usernamePassword(etc)]) { ... }

What are all the credential types that can be used with withCredentials, what are their keywords and parameters, and how do they appear in the Jenkins server "credentials" GUI?

Share Improve this question asked Feb 3 at 21:30 cowlinatorcowlinator 8,9037 gold badges56 silver badges69 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Plugins can add their own credential types, but these are the most commonly used built-in credential types (as of Jenkins 2.452.1):

usernamePassword(               // "Username and Password" in the GUI
    credentialsId: 'cred',
    usernameVariable: 'user',
    passwordVariable: 'pass')

sshUserPrivateKey(              // "Username with private key" in the GUI
    credentialsId: 'cred',
    keyFileVariable: 'keyFilepath',
    usernameVariable: 'user',   // optional
    passphraseVariable: 'pass') // optional

string(                         // "Secret text" in the GUI
    credentialsId: 'cred',
    variable: 'str')

file(                           // "Secret file" in the GUI
    credentialsId: 'cred',
    variable: 'filePath')

certificate(                    // "Certificate" in the GUI, for PKCS#12 certificates
    credentialsId: 'cred',
    keystoreVariable: 'keystore',
    aliasVariable: 'alias',     // optional
    passwordVariable: 'pass')   // optional

You can find many more types in the documentation for the credentials binding plugin, but many of those listed do not seem to (by default) have any way of creating that type of credential via the GUI. It may be that they require plugins.

转载请注明原文地址:http://www.anycun.com/QandA/1744748855a87062.html