Complete the code to use the Jenkins Credentials plugin to retrieve a secret text.
def secret = com.cloudbees.plugins.credentials.CredentialsProvider.findCredentialById('[1]', com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials.class, Jenkins.instance)
The findCredentialById method requires the ID of the stored secret. Here, my-secret-id is the correct ID placeholder.
Complete the code to access the secret text value from the credentials object.
def secretText = secret.[1]()
The getPassword() method returns the secret text stored in the credentials object.
Fix the error in the code to correctly retrieve credentials in a Jenkins pipeline script.
withCredentials([string(credentialsId: '[1]', variable: 'SECRET')]) { echo "Secret is $SECRET" }
The credentialsId must exactly match the ID of the stored secret, here my-secret-id.
Fill both blanks to define a credentials binding for username and password in a Jenkins pipeline.
withCredentials([usernamePassword(credentialsId: '[1]', usernameVariable: '[2]', passwordVariable: 'PASSWORD')]) { echo "User is $USERNAME" }
The credentialsId is the ID of the username-password credential. The usernameVariable must match the variable used in the script, here USERNAME.
Fill all three blanks to create a map of secrets filtered by a condition using Jenkins credentials in Groovy.
def secretsMap = credentials.findAll { cred -> cred.id.[3]('prod') }.collectEntries { cred -> [[1], [2]] }
The map uses cred.id as keys and cred.getPassword().getPlainText() as values. The filter uses contains to select credentials with 'prod' in their ID.