Complete the code to specify the credential type for a username and password in Jenkins pipeline.
withCredentials([usernamePassword(credentialsId: 'my-creds', usernameVariable: 'USER', passwordVariable: '[1]')]) { echo "User is $USER" }
The passwordVariable must be set to 'PASSWORD' to correctly map the password from the credentials.
Complete the code to use a secret text credential in a Jenkins pipeline.
withCredentials([string(credentialsId: 'api-key', variable: '[1]')]) { echo "Key is $API_KEY" }
The variable name should match the usage in the echo statement, which is API_KEY.
Fix the error in the Jenkins pipeline code to correctly use SSH private key credentials.
withCredentials([sshUserPrivateKey(credentialsId: 'ssh-creds', keyFileVariable: '[1]', usernameVariable: 'SSH_USER')]) { sh 'ssh -i $SSH_KEY $SSH_USER@host' }
The keyFileVariable must be SSH_KEY to match the shell command usage.
Fill both blanks to create a Jenkins pipeline snippet that uses a certificate credential.
withCredentials([certificate(credentialsId: '[1]', keystoreVariable: '[2]', passwordVariable: 'CERT_PASS')]) { echo "Using keystore $KEYSTORE" }
The credentialsId should be the ID of the certificate, here 'cert-id'. The keystoreVariable should be 'keystore' to match the echo statement.
Fill all three blanks to create a Jenkins pipeline snippet that uses a Docker registry credential.
withCredentials([usernamePassword(credentialsId: '[1]', usernameVariable: '[2]', passwordVariable: '[3]')]) { sh 'docker login -u $[2] -p $[3] myregistry.com' }
The credentialsId is 'docker-creds'. The usernameVariable is 'DOCKER_USER' and the passwordVariable is 'DOCKER_PASS' to match the shell command usage.