Complete the code to start a declarative Jenkins pipeline.
pipeline {
agent [1]
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
}
}node which is scripted pipeline syntax.master which is deprecated.docker without proper configuration.The agent any directive tells Jenkins to run the pipeline on any available agent.
Complete the code to define a stage named 'Test'.
pipeline {
agent any
stages {
stage([1]) {
steps {
echo 'Testing...'
}
}
}
}The stage name is given as a string. Here, the stage is named 'Test'.
Fix the error in the steps block to print 'Deploying...'.
pipeline {
agent any
stages {
stage('Deploy') {
steps {
[1] 'Deploying...'
}
}
}
}print which is not recognized in Jenkins pipelines.println which is not valid here.In Jenkins declarative pipelines, echo is used to print messages to the console.
Fill both blanks to add a post action that always runs and echoes 'Cleaning up'.
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
}
post {
[1] {
steps {
[2] 'Cleaning up'
}
}
}
}success or failure instead of always.print instead of echo.The post section can have conditions like always to run steps regardless of build result. Inside it, echo prints the message.
Fill all three blanks to create an environment variable named 'VERSION' with value '1.0' and echo it in the build stage.
pipeline {
agent any
environment {
[1] = [2]
}
stages {
stage('Build') {
steps {
[3] "Version is $VERSION"
}
}
}
}print instead of echo.Environment variables are declared with a name and value. Here, VERSION is set to "1.0". Then echo prints the message using the variable.