Complete the code to start a Jenkins pipeline with a simple stage.
pipeline {
agent any
stages {
stage('Build') {
steps {
[1] 'echo Building...'
}
}
}
}The sh step runs shell commands in Jenkins pipelines.
Complete the code to trigger a Jenkins job remotely using a token.
curl -X POST http://jenkins.example.com/job/myjob/build?token=[1]The token mytoken123 is used to authenticate remote triggers.
Fix the error in the Jenkinsfile to correctly define an environment variable.
pipeline {
agent any
environment {
MY_VAR = [1]
}
stages {
stage('Test') {
steps {
sh 'echo $MY_VAR'
}
}
}
}Environment variables in Jenkinsfile need to be strings with double quotes.
Fill both blanks to create a Jenkins pipeline stage that runs only on the 'main' branch.
stage('Deploy') { when { [1] 'main' } steps { [2] 'echo Deploying to production' } }
The when { branch 'main' } condition uses branch to check the branch. The sh step runs shell commands.
Fill all three blanks to define a Jenkins pipeline with a parameter and use it in a stage.
pipeline {
agent any
parameters {
string(name: '[1]', defaultValue: 'world', description: 'Who to greet')
}
stages {
stage('Greet') {
steps {
sh "echo Hello, [2]!"
}
}
}
environment {
GREETING = '[3]'
}
}The parameter name is NAME. To use it in shell, use ${params.NAME}. The environment variable GREETING is set to the default world.