0
0
Jenkinsdevops~10 mins

Credentials plugin for secrets in Jenkins - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to use the Jenkins Credentials plugin to retrieve a secret text.

Jenkins
def secret = com.cloudbees.plugins.credentials.CredentialsProvider.findCredentialById('[1]', com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials.class, Jenkins.instance)
Drag options to blanks, or click blank then click option'
Amy-secret-id
Bsecret-text
Ccredentials-id
Dpassword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the secret value instead of the credential ID
Using an incorrect class type
2fill in blank
medium

Complete the code to access the secret text value from the credentials object.

Jenkins
def secretText = secret.[1]()
Drag options to blanks, or click blank then click option'
AgetSecret
BgetPlainText
CgetPassword
DgetSecretText
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method that does not exist
Confusing with other getter methods
3fill in blank
hard

Fix the error in the code to correctly retrieve credentials in a Jenkins pipeline script.

Jenkins
withCredentials([string(credentialsId: '[1]', variable: 'SECRET')]) {
  echo "Secret is $SECRET"
}
Drag options to blanks, or click blank then click option'
Amy-secret-id
Bsecret-id
Ccredentials
Dmy-secret
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong or partial ID
Using the variable name instead of the ID
4fill in blank
hard

Fill both blanks to define a credentials binding for username and password in a Jenkins pipeline.

Jenkins
withCredentials([usernamePassword(credentialsId: '[1]', usernameVariable: '[2]', passwordVariable: 'PASSWORD')]) {
  echo "User is $USERNAME"
}
Drag options to blanks, or click blank then click option'
Auser-pass-id
BUSERNAME
CUSER
Dpassword
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names
Mixing up username and password variables
5fill in blank
hard

Fill all three blanks to create a map of secrets filtered by a condition using Jenkins credentials in Groovy.

Jenkins
def secretsMap = credentials.findAll { cred -> cred.id.[3]('prod') }.collectEntries { cred -> [[1], [2]] }
Drag options to blanks, or click blank then click option'
Acred.id
Bcred.getPassword().getPlainText()
CstartsWith
Dcontains
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong property names
Using incorrect string method for filtering