Complete the code to specify the SCM repository URL in a Jenkins pipeline.
pipeline {
agent any
stages {
stage('Checkout') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/main']], userRemoteConfigs: [[url: '[1]']]])
}
}
}
}The SCM repository URL must be specified in the url field to tell Jenkins where to get the code.
Complete the code to define the branch to checkout in the Jenkins pipeline.
pipeline {
agent any
stages {
stage('Checkout') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '[1]']], userRemoteConfigs: [[url: 'https://github.com/example/repo.git']]])
}
}
}
}The branch name tells Jenkins which branch to pull from the repository. 'main' is the default branch in many repositories.
Fix the error in the Jenkins pipeline code to correctly checkout the code from SCM.
pipeline {
agent any
stages {
stage('Checkout') {
steps {
checkout([$class: '[1]', branches: [[name: '*/main']], userRemoteConfigs: [[url: 'https://github.com/example/repo.git']]])
}
}
}
}The correct class name for Git SCM in Jenkins pipeline is 'GitSCM'. Using the wrong class name causes errors.
Fill both blanks to configure polling SCM changes and trigger builds automatically.
pipeline {
agent any
triggers {
pollSCM('[1]')
}
stages {
stage('Checkout') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '[2]']], userRemoteConfigs: [[url: 'https://github.com/example/repo.git']]])
}
}
}
}The pollSCM trigger uses a cron syntax to check for changes every 5 minutes. The branch name 'main' specifies which branch to monitor.
Fill all three blanks to define a Jenkins pipeline that checks out code, builds, and archives artifacts.
pipeline {
agent any
stages {
stage('Checkout') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '[1]']], userRemoteConfigs: [[url: '[2]']]])
}
}
stage('Build') {
steps {
sh '[3]'
}
}
}
post {
success {
archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true
}
}
}The pipeline checks out the 'main' branch from the given Git URL, then runs the Maven build command to package the project, and finally archives the built JAR files.