Complete the code to define a global credential in Jenkins using the Credentials plugin.
credentials {
usernamePassword {
id = '[1]'
username = 'admin'
password = 'secret'
}
}The ID global-cred is used to define a global credential accessible across Jenkins.
Complete the code to reference a folder-scoped credential in a Jenkins pipeline.
pipeline {
agent any
stages {
stage('Use Credential') {
steps {
withCredentials([usernamePassword(credentialsId: '[1]', usernameVariable: 'USER', passwordVariable: 'PASS')]) {
sh 'echo $USER'
}
}
}
}
}The credential ID folder-cred is used to access credentials scoped to a specific folder.
Fix the error in the Jenkinsfile to correctly use a folder-scoped credential.
pipeline {
agent any
stages {
stage('Test') {
steps {
withCredentials([usernamePassword(credentialsId: '[1]', usernameVariable: 'USER', passwordVariable: 'PASS')]) {
sh 'echo $PASS'
}
}
}
}
}The correct credential ID for folder scope is folder-cred. Using an incorrect ID causes errors.
Fill both blanks to create a folder-scoped credential and use it in a Jenkins pipeline.
folder('MyFolder') { credentials { usernamePassword { id = '[1]' username = 'user1' password = 'pass1' } } } pipeline { agent any stages { stage('Use Folder Credential') { steps { withCredentials([usernamePassword(credentialsId: '[2]', usernameVariable: 'USER', passwordVariable: 'PASS')]) { sh 'echo $USER' } } } } }
Both blanks use folder-cred to define and reference the folder-scoped credential.
Fill all three blanks to define a global credential, a folder credential, and use the folder credential in a pipeline.
credentials {
usernamePassword {
id = '[1]'
username = 'admin'
password = 'adminpass'
}
}
folder('ProjectFolder') {
credentials {
usernamePassword {
id = '[2]'
username = 'projuser'
password = 'projpass'
}
}
}
pipeline {
agent any
stages {
stage('Run') {
steps {
withCredentials([usernamePassword(credentialsId: '[3]', usernameVariable: 'USER', passwordVariable: 'PASS')]) {
sh 'echo $USER'
}
}
}
}
}The global credential uses global-cred, the folder credential uses folder-cred, and the pipeline uses the folder credential folder-cred.