0
0
Jenkinsdevops~10 mins

Credential types and storage 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 specify the credential type for a username and password in Jenkins pipeline.

Jenkins
withCredentials([usernamePassword(credentialsId: 'my-creds', usernameVariable: 'USER', passwordVariable: '[1]')]) { echo "User is $USER" }
Drag options to blanks, or click blank then click option'
APASSWORD
BPASS
CSECRET
DTOKEN
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'PASS' or 'TOKEN' which are not recognized variable names in this context.
2fill in blank
medium

Complete the code to use a secret text credential in a Jenkins pipeline.

Jenkins
withCredentials([string(credentialsId: 'api-key', variable: '[1]')]) { echo "Key is $API_KEY" }
Drag options to blanks, or click blank then click option'
AAPIKEY
BSECRET
CKEY
DAPI_KEY
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'APIKEY' without underscore does not match the echo statement.
3fill in blank
hard

Fix the error in the Jenkins pipeline code to correctly use SSH private key credentials.

Jenkins
withCredentials([sshUserPrivateKey(credentialsId: 'ssh-creds', keyFileVariable: '[1]', usernameVariable: 'SSH_USER')]) { sh 'ssh -i $SSH_KEY $SSH_USER@host' }
Drag options to blanks, or click blank then click option'
AKEY_FILE
BSSH_PRIVATE_KEY
CSSH_KEY
DPRIVATE_KEY
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name different from the one used in the shell command.
4fill in blank
hard

Fill both blanks to create a Jenkins pipeline snippet that uses a certificate credential.

Jenkins
withCredentials([certificate(credentialsId: '[1]', keystoreVariable: '[2]', passwordVariable: 'CERT_PASS')]) { echo "Using keystore $KEYSTORE" }
Drag options to blanks, or click blank then click option'
Acert-id
Bkeystore
Cstore
Dcert-store
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cert-store' or 'store' which do not match the echo variable.
5fill in blank
hard

Fill all three blanks to create a Jenkins pipeline snippet that uses a Docker registry credential.

Jenkins
withCredentials([usernamePassword(credentialsId: '[1]', usernameVariable: '[2]', passwordVariable: '[3]')]) { sh 'docker login -u $[2] -p $[3] myregistry.com' }
Drag options to blanks, or click blank then click option'
Adocker-creds
BDOCKER_USER
CDOCKER_PASS
DREGISTRY_PASS
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'REGISTRY_PASS' instead of 'DOCKER_PASS' causes mismatch in variable usage.