Scripted Syntax vs Declarative Syntax
- Style:
- Scripted syntax is imperative
- Declrative Syntax is declarative
- Scripting:
- Scripted: Uses Groovy lanugage constructs
- Declarative: Jenkins DSL
- UI Tooling
- Declarative: Blue Ocean
- Example:
- Scripted:
node('HMS') { stage ('git') { git 'https://github.com/dummygitrepos/gameoflife.git' } stage ('compile'){ sh 'mvn package' } } - Declarative:
pipeline { agent { label 'HMS' } stages { stage ('SCM') { steps { git 'https://github.com/dummygitrepos/gameoflife.git' } }, stage ('Compile') { steps { sh 'mvn package' } } } }
- Scripted:
Scripted Syntax
- node: This line tells jenkins on which node it should run this part of pipeline
- syntax:
- node(‘HMS’)
- node (‘HMS && QA’)
- Then node will have a closure {}

- syntax:
- stage:
- This is also a closure will allows to run the steps
- Should have a name.
- steps:
- Jenkins DSL Commands are referred as steps.
- This is lowest/atomic level of functionality defined by the DSL.
- Refer Here for all the available steps
- Now lets look at git steps and understand different ways of defining a step
- Navigate to git the above link

- Refer the docs from here
- Every step has arguments
- Different versions of git step
1. git 'https://github.com/dummygitrepos/gameoflife.git' 2. git url: 'https://github.com/dummygitrepos/gameoflife.git', branch: 'master' - Navigate to git the above link
- Relation b/w node stage and steps are as shown below

Declarative Pipeline Structure
- The Structure is represented below

- Refer Here for declarative pipeline
- Agents in pipeline: Refer Here
- Example syntax
pipeline { agent { label 'HRMS && QA' } }
