In Declarative Pipeline syntax, the pipeline block defines all the work done throughout your entire Pipeline.
Jenkinsfile (Declarative Pipeline)
pipeline { agent any // Execute this Pipeline or any of its stages, on any available agent. stages { stage('Build') { //Defines the "Build" stage. steps { // Perform some steps related to the "Build" stage. } } stage('Test') { //Defines the "Test" stage. steps { // Perform some steps related to the "Test" stage. } } stage('Deploy') { //Defines the "Deploy" stage. steps { // Perform some steps related to the "Deploy" stage. } } } }
In Scripted Pipeline syntax, one or more node blocks do the core work throughout the entire Pipeline. Although this is not a mandatory requirement of Scripted Pipeline syntax, confining your Pipeline’s work inside of a node block does two things:
Schedules the steps contained within the block to run by adding an item to the Jenkins queue. As soon as an executor is free on a node, the steps will run.
Creates a workspace (a directory specific to that particular Pipeline) where work can be done on files checked out from source control.
Caution: Depending on your Jenkins configuration, some workspaces may not get automatically cleaned up after a period of inactivity. See tickets and discussion linked from JENKINS-2111 for more information.
Jenkinsfile (Scripted Pipeline)
node { //Execute this Pipeline or any of its stages, on any available agent. stage('Build') { // Defines the "Build" stage. stage blocks are optional in Scripted Pipeline syntax. However, implementing stage blocks in a Scripted Pipeline provides clearer visualization of each `stage’s subset of tasks/steps in the Jenkins UI. // Perform some steps related to the "Build" stage. } stage('Test') { //Defines the "Test" stage. // Defines the "Test" stage } stage('Deploy') { //Defines the "Deploy" stage. // Defines the "Deploy" stage. } }