0
0
Jenkinsdevops~20 mins

Credential types and storage in Jenkins - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Jenkins Credential Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Jenkins Credential Types

Which Jenkins credential type is best suited to store a username and password pair securely?

AUsername with password
BCertificate
CSSH Username with private key
DSecret text
Attempts:
2 left
💡 Hint

Think about which type explicitly stores both username and password together.

💻 Command Output
intermediate
2:00remaining
Jenkins CLI Credential Listing Output

What is the output of the following Jenkins CLI command when listing credentials in a folder named 'projectA'?

java -jar jenkins-cli.jar -s http://jenkins.example.com/ list-credentials projectA
AError: No credentials found in folder 'projectA'
B
[id: 'cred1', type: 'Username with password', description: 'GitHub creds']
[id: 'cred2', type: 'Secret text', description: 'API token']
CSyntaxError: Invalid command format
D[id: 'cred1', type: 'SSH Username with private key', description: 'Deploy key']
Attempts:
2 left
💡 Hint

Assume the folder 'projectA' contains two credentials: one username/password and one secret text.

Configuration
advanced
3:00remaining
Jenkinsfile Using Credentials Binding

Which Jenkinsfile snippet correctly uses the 'usernamePassword' credentials binding to inject username and password environment variables?

A
pipeline {
  agent any
  environment {
    CREDS = credentials('my-cred-id')
  }
  stages {
    stage('Build') {
      steps {
        echo "User: $CREDS_USR"
        echo "Pass: $CREDS_PSW"
      }
    }
  }
}
B
pipeline {
  agent any
  environment {
    USER = credentials('my-cred-id')
  }
  stages {
    stage('Build') {
      steps {
        echo "User: $USER"
      }
    }
  }
}
C
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        withCredentials([string(credentialsId: 'my-cred-id', variable: 'TOKEN')]) {
          echo "Token: $TOKEN"
        }
      }
    }
  }
}
D
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        withCredentials([usernamePassword(credentialsId: 'my-cred-id', usernameVariable: 'USER', passwordVariable: 'PASS')]) {
          echo "User: $USER"
          echo "Pass: $PASS"
        }
      }
    }
  }
}
Attempts:
2 left
💡 Hint

Look for the correct use of withCredentials and variable names for username and password.

Troubleshoot
advanced
2:00remaining
Jenkins Credential Access Error

A Jenkins pipeline fails with the error: java.lang.IllegalArgumentException: No credentials found with id 'deploy-key'. What is the most likely cause?

AThe pipeline syntax for accessing credentials is incorrect and causes this error.
BThe Jenkins agent does not have internet access to fetch the credential.
CThe credential with id 'deploy-key' does not exist or is not accessible in the current folder or global scope.
DThe Jenkins master is offline and cannot provide credentials.
Attempts:
2 left
💡 Hint

Consider where credentials are stored and their scope in Jenkins.

Best Practice
expert
3:00remaining
Secure Storage of API Tokens in Jenkins

Which is the most secure and recommended way to store and use API tokens in Jenkins pipelines?

AStore the API token as a 'Secret text' credential and use <code>withCredentials</code> to inject it as an environment variable during the pipeline run.
BHardcode the API token directly in the Jenkinsfile for easy access.
CStore the API token in a plain text file on the Jenkins master and read it during the build.
DUse the 'Username with password' credential type but leave the username empty.
Attempts:
2 left
💡 Hint

Think about avoiding exposure of secrets and following Jenkins best practices.