Problem Statement
What are the two types of Jenkinsfile syntax?
Explanation
Declarative Pipeline is the newer, recommended syntax with a more structured, opinionated format. It starts with a pipeline block and requires specific sections like agent, stages, and steps. Declarative syntax is easier to read and write, has built-in validation, supports restart from stage, and provides a clearer structure. Example: pipeline { agent any; stages { stage('Build') { steps { sh 'make' } } } }.
Scripted Pipeline is the original, more flexible syntax based on Groovy. It starts with a node block and allows full Groovy programming capabilities including variables, loops, functions, and complex logic. Scripted pipelines offer more flexibility but require more Groovy knowledge and can become harder to maintain. Example: node { stage('Build') { sh 'make' } }.
Declarative is recommended for most use cases due to better structure, easier learning curve, and built-in best practices. Use Scripted only when you need complex logic that Declarative doesn't support well, though Declarative's script step allows embedded Groovy for when you need flexibility. Understanding both types is important as you'll encounter legacy Scripted pipelines while new development should prefer Declarative.
