Complete the code to define a Jenkins pipeline that runs on any available agent.
pipeline {
agent [1]
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
}
}The agent any directive tells Jenkins to run the pipeline on any available agent, which helps speed up builds by using available resources.
Complete the code to add a stage named 'Test' in the Jenkins pipeline.
pipeline {
agent any
stages {
stage('[1]') {
steps {
echo 'Running tests...'
}
}
}
}The stage name should be 'Test' to indicate this stage runs tests, which is important for catching errors early and improving development speed.
Fix the error in the Jenkins pipeline syntax by completing the missing keyword.
pipeline {
agent any
stages {
stage('Deploy') {
[1] {
echo 'Deploying application...'
}
}
}
}The steps block is required inside a stage to define the commands Jenkins runs. Missing it causes syntax errors.
Fill both blanks to create a post-build action that always runs and sends a notification.
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
}
post {
[1] {
[2] 'Build finished.'
}
}
}The always block runs after the pipeline regardless of success or failure. Inside it, echo prints a message to notify that the build finished.
Fill all three blanks to create a simple pipeline with environment variables and a shell command.
pipeline {
agent any
environment {
[1] = 'production'
}
stages {
stage('Deploy') {
steps {
sh '[2] deploy to [3]'
}
}
}
}ENVIRONMENT is the variable name set to 'production'. The sh step runs a shell command that echoes the deploy message using the variable $ENVIRONMENT.