Complete the code to define a basic Jenkins pipeline stage named 'Build'.
stage('Build') { steps { [1] 'mvn clean package' } }
The sh step runs shell commands in Jenkins pipelines. Here, it runs the Maven build command.
Complete the code to trigger the pipeline on SCM changes using polling.
pipeline {
agent any
triggers {
[1] 'H/5 * * * *'
}
}The pollSCM trigger checks the source code management for changes using a cron schedule.
Fix the error in the Jenkins pipeline snippet to archive the build artifact 'target/app.jar'.
post {
success {
[1] artifacts: 'target/app.jar'
}
}The correct Jenkins step to save build outputs is archiveArtifacts.
Fill both blanks to define a stage that deploys the app only if the branch is 'main'.
stage('Deploy') { when { [1] '[2]' } steps { echo 'Deploying application' } }
The when condition uses branch 'main' to run the stage only on the main branch.
Fill all three blanks to create a pipeline that builds, tests, and deploys with proper stages.
pipeline {
agent any
stages {
stage('Build') {
steps {
[1] 'mvn clean package'
}
}
stage('Test') {
steps {
[2] 'mvn test'
}
}
stage('Deploy') {
steps {
echo '[3]'
}
}
}
}Use sh to run shell commands for build and test stages. The deploy stage echoes a message.