Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a node, stage, and step in Jenkins pipelines?

I'm trying to understand how to structure my Jenkins 2.7 pipeline groovy script. I've read through the pipeline tutorial, but feel that it could expand more on these topics.

I can understand that a pipeline can have many stages and each stage can have many steps. But what is the difference between a step(); and a method call inside a stage, say sh([script: "echo hello"]);. Should nodes be inside or outside of stages? Should the overall properties of a job be inside or outside a node?

Here is my current structure on an ubuntu master node:

#!/usr/bin/env groovy  node('master') {     properties([         [$class: 'BuildDiscarderProperty', strategy: [$class: 'LogRotator', numToKeepStr: '10']]     ]);      stage 'Checkout'         checkout scm      stage 'Build'         sh([script: "make build"]);      archive("bin/*"); } 
like image 871
tarabyte Avatar asked Sep 17 '16 16:09

tarabyte


People also ask

What is node and stage in Jenkins pipeline?

node specifies where something shall happen. You give a name or a label, and Jenkins runs the block there. stage structures your script into a high-level sequence. Stages show up as columns in the Pipeline Stage view with average stage times and colours for the stage result.

What are the different stages in Jenkins pipeline?

It contains a collection of states such as build, deploy, test and release. These jobs or events are interlinked with each other. Every state has its jobs, which work in a sequence called a continuous delivery pipeline.

What is a node in Jenkins pipeline?

Node. A node is a machine which is part of the Jenkins environment and is capable of executing a Pipeline. Also, a node block is a key part of Scripted Pipeline syntax.

What is step in Jenkins?

Jenkins Pipeline allows you to compose multiple steps in an easy way that can help you model any sort of automation process. Think of a "step" like a single command which performs a single action. When a step succeeds it moves onto the next step. When a step fails to execute correctly the Pipeline will fail.


1 Answers

The concepts of node, stage and step are different:

  • node specifies where something shall happen. You give a name or a label, and Jenkins runs the block there.

  • stage structures your script into a high-level sequence. Stages show up as columns in the Pipeline Stage view with average stage times and colours for the stage result.

  • step is one way to specify what shall happen. sh is of a similar quality, it is a different kind of action. (You can also use build for things that are already specified as projects.)

So steps can reside within nodes, (if they don't, they are executed on the master), and nodes and steps can be structured into an overall sequence with stages.

like image 186
chris_f Avatar answered Oct 11 '22 18:10

chris_f