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 stage
s and each stage
can have many step
s. But what is the difference between a step();
and a method call inside a stage
, say sh([script: "echo hello"]);
. Should node
s be inside or outside of stage
s? 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/*"); }
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.
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.
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.
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.
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 step
s can reside within node
s, (if they don't, they are executed on the master), and node
s and step
s can be structured into an overall sequence with stage
s.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With