0
0
Jenkinsdevops~10 mins

WithCredentials block usage 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 credentials ID inside the withCredentials block.

Jenkins
withCredentials([usernamePassword(credentialsId: '[1]', usernameVariable: 'USER', passwordVariable: 'PASS')]) {
    echo "Username is $USER"
}
Drag options to blanks, or click blank then click option'
Asecret123
BcredentialsId
Cuser_pass
Dmy-credentials-id
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names instead of the actual credentials ID.
Leaving the credentialsId blank.
2fill in blank
medium

Complete the code to use a secret text credential inside the withCredentials block.

Jenkins
withCredentials([string(credentialsId: '[1]', variable: 'TOKEN')]) {
    sh 'echo $TOKEN'
}
Drag options to blanks, or click blank then click option'
Atoken-secret
Buser-pass
Cmy-password
Dapi-key
Attempts:
3 left
💡 Hint
Common Mistakes
Using a usernamePassword ID for a secret text block.
Using the wrong variable name.
3fill in blank
hard

Fix the error in the withCredentials block to correctly bind the username and password.

Jenkins
withCredentials([usernamePassword(credentialsId: 'cred-id', usernameVariable: '[1]', passwordVariable: 'PASS')]) {
    echo "User is $USER"
}
Drag options to blanks, or click blank then click option'
AUSERNAME
BUSER
Cuser
Dusername
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different case for the variable name.
Mismatching variable names between declaration and usage.
4fill in blank
hard

Fill both blanks to correctly use multiple credentials inside the withCredentials block.

Jenkins
withCredentials([usernamePassword(credentialsId: '[1]', usernameVariable: 'USER', passwordVariable: '[2]')]) {
    echo "User: $USER, Password: $PASS"
}
Drag options to blanks, or click blank then click option'
Amulti-cred-id
BPASSWORD
CPASS
Duserpass
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names for passwordVariable.
Using incorrect credentialsId.
5fill in blank
hard

Fill all three blanks to correctly use a file credential inside the withCredentials block.

Jenkins
withCredentials([file(credentialsId: '[1]', variable: '[2]')]) {
    sh 'cat $[3]'
}
Drag options to blanks, or click blank then click option'
Afile-cred-id
BFILE_PATH
DfileVar
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in declaration and usage.
Using wrong credentialsId.