Check credentials by name if they already exist in Jenkins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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