Declarative Pipeline
- The structural layout of the pipeline project appears as shown below
pipeline
{
agent any
stages {
stage('<name of stage>') {
steps {
...
}
post {
}
}
stage('<name of stage>') {
steps {
...
}
post {
}
}
}
post {
}
}
- Visual representation of structure

Triggering Jobs
- In the free style project, we have the following options

- In the Pipeline project jenkins ui shows the following options

- To configure the pipelines in the
- Free style project: => UI
- Scripted pipeline, a properies can be specified
- Declarative pipeline, triggers
- Build after Other projects are built:
- Freestyle
- Save the configuration

- Build the other project

- Upstream project for this would be starterproject

- For starter project freestyle project would be Downstream

- Save the configuration
- Scripted:
- Refer Here for the changes done in jenkinsfile
- Declartive Pipeline:
- For writing triggers Refer Here
- Refer Here for the changes done
- Freestyle
- Build periodically:
- In this case we want to trigger the build based on some schedule, and in linux to schedule we have cron job.
- Jenkins uses this cron syntax to execute the jobs on schedule
- To understand cronjobs Refer Here
- Lets try to configure the
- Free style project to run every 1/2 hour on weekdays (remove the upstream)

- scripted pipeline to run every 3 hours on weekends (remove the upstream)
- Refer Here for the changeset
- declarative pipeline to run every day @ 11:45 PM on week days
- Refer Here for the changeset
- Free style project to run every 1/2 hour on weekdays (remove the upstream)
- Poll SCM: In this we can poll the version control remote for changes & when the changes occur, we can trigger the build. But we need to configure how frequently we need to poll the SCM using cron syntax
- Declarative pipeline: Lets configure for polling scm every 5 minutes
- Refer Here for the changeset

- Refer Here for the changeset
- Declarative pipeline: Lets configure for polling scm every 5 minutes
User Input
- Using this step, we can stop and wait for the user response
- Refer Here
- Refer Here for changes
Parameters
- when we build the project we will have a need to use parameters
- Lets create some parameters for free style project

- Lets create parameters where user will select
- which branch to build

- what will be maven goal => default goal is package

- Now lets use this PARAMETERS in selecting the branch

- For maven goal

- Navigate to the project page

- which branch to build
- Lets give the same parameters from
- scripted pipeline: Refer Here for the changes
- declarative pipeline:
- Refer Here for the documentation
- Refer Here for the changes done
Note
- Pipeline steps reference Refer Here
