...
Table of Contents | ||||
---|---|---|---|---|
|
Structure
The Jenkins DevOps pipeline is defined in a “Jenkinsfile” ‘Jenkinsfile’ (by with the default named filename Jenkinsfile
) and has the following structure (most detail omitted). Paired curly braces ”{ }"
an overall structure summarised below. Note that paired curly braces - { }
- denote the start and end of a scoped section. Comments are “can be created in a block (/* comment like this */
” (inline) or “inline (//
” (til end of line)comment like this
).
Code Block |
---|
pipeline { /* outermost scope # Outermost scope agent { ... } */ agent { ... } # What are the default agent(s) upon which /* where will this run? */ Stages execute? parameters { ... } /* What is it being fed? # What values are required if the pipeline is invoked */interactively? environment { ... } /* # whatWhat other(global) variables are needed? */ stages { /* operational container # */ Operational container stage { ... } /* first sequence of steps # First Stage (sequence of executable steps) */ stageagent { ... } /* next # Which agent is used to execute this Stage? environment { ... } */ # What variables are needed? (local to this stage) ... } steps { { /*step end} of stages # Executable step */ } ... } //# endEnd of pipeline |
To understand these sections in more detail, refer to your Jenkins documentation. We present only the MettleCI specific things you need to know. Note that Jenkins offers flexibility in where some of these sections are placed, and in some cases, allows repetition at different scopes. Note also that there are additional things you could put in to just about every section, and that some sections may be repeated at a given scope level.
Sections before “stages”
Agent section
The agent section denotes what class of machines your pipeline can be executed on. For a CI/CD pipeline, you only need to specify this once since all projects are at the same release level. For an upgrade pipeline you may want to specify the agents within the stage so that different stages run on different release levels. In the example below the label should match the label you gave your agent on the MettleCI host when you set it up. Pipelines will stall if no running agent with the (matching set of) label(s) is found.
Code Block |
---|
agent {
label 'mettleci:datastage11.7.1'
} |
Parameters section
The parameters section enumerates the parameters to the pipeline with their default values. The four parameters used in the template, and their meanings are discussed in /wiki/spaces/MCIDOC/pages/741310474
Info |
---|
note that parameters are immutable, and once set at pipeline (or scope section) start, cannot be changed |
Code Block |
---|
parameters { first Stage stage { ... } # Second Stage ... } string(name: 'domainName', defaultValue: 'demo4-svcs.datamigrators.io:59445', description: 'DataStage Service Tier') # End of Stage definitions } string(name: 'serverName', defaultValue: 'demo4-engn.datamigrators.io', description: 'DataStage Engine Tier') string(name: 'projectName', defaultValue: 'wwi_jenkins_ds117', description: 'Logical (unsuffixed) Project Name') string(name: 'environmentId', defaultValue: 'ci', description: 'Environment Identifer') } |
When run interactively, the user will be prompted for these at pipeline start time like so:
...
# End of Pipeline |
Note that Jenkins offers some flexibility in the structure of the pipeline, and in some cases allows repetition at different scopes. For example, a single Step can optionally contain another Stages {...}
container which defines more sub-Stages). To understand these sections in more detail refer to the Jenkins documentation.
Input Values
Parameters section
The parameters
section enumerates the parameters to the pipeline with their default values. Note that parameters values are immutable, and once a pipeline is invoked with parameter values those values cannot be changed.
Info |
---|
Note that the sample Jenkins pipelines supplied with MettleCI do not make use of parameters as all pipeline values are supplied as Node Properties. |
Environment Section
The environment
section allows you to derive and set further useful variables. The template pipeline composes the suffixed DataStage project and copies one of the parameters to an all uppercased variable for convenience later.
...
Environment variables can be further manipulated in the same or subsequent environment {}
section(s), unlike parameters which, once obtained, cannot be changed
Stages Section
The stages Stages section (see terminology) is a container for an arbitrary number of individual stagesStage containers, which
Contains Steps - the executable actions
which are normally run in sequence . In the template pipeline there are three, “Deploy”, “Test”, and “Promote”(but can be configure to run in parallel).
Stage section notes
Each stage section begins with a label, which is a quoted arbitrary text string displayed on the pipeline diagram in Blue Ocean when viewing the pipeline,
...