import com.cloudbees.plugins.credentials.CredentialsProvider
def credsList = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(com.cloudbees.plugins.credentials.Credentials.class,Jenkins.instance,null,null);
def creds = credsList.findResult { it.id == "<YOUR-CREDS-ID>" ? it : null }
println("apiToken: ${creds.apiToken}")
参考:https://issues.jenkins.io/browse/JENKINS-48552
https://github.com/jenkinsci/gitlab-plugin/issues/536
网友评论