Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Check credentials by name if they already exist in Jenkins
import com.cloudbees.plugins.credentials.*
import com.cloudbees.plugins.credentials.common.*
def credentials_for_username(String username) {
def username_matcher = CredentialsMatchers.withUsername(username)
def available_credentials =
CredentialsProvider.lookupCredentials(
StandardUsernameCredentials.class,
Jenkins.getInstance(),
hudson.security.ACL.SYSTEM
)
return CredentialsMatchers.firstOrNull(available_credentials, username_matcher)
}
credentials_for_username("username_HERE")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.