Spinnaker Pipeline Template: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 53: Line 53:
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
spin pipeline save --file "<pipeline-json-representation>"
spin pipeline save --file "<pipeline-json-representation>"
</syntaxhighlight>
Upon saving, the pipeline instance gets a unique ID.
The pipeline can be obtained from the backend with:
<syntaxhighlight lang='bash'>
spin pipeline list --application "<application-name>"
</syntaxhighlight>
or:
<syntaxhighlight lang='bash'>
spin pipeline get --application"<application-name>"--name "<pipeline-name>"
</syntaxhighlight>
</syntaxhighlight>



Revision as of 22:32, 30 May 2023

External

Internal

Overview

Multiple pipeline instances can be created from a pipeline template by providing values to the variables defined in the template. Any changes made to the pipeline template even after it has been instantiated as one or more pipelines, are propagated to the instantiated pipelines automatically. The pipeline is instantiated and parameterized by the Orca engine during the pipeline execution. A pipeline template has two components: the template and the configuration.

The Process of Creating a Pipeline from Template

The template is expressed as a JSON file, similar to the one provided in the Template Example below.

The pipeline template JSON file optionally includes a variables section, that lists template variables (name, type and default values).

The template is saved to the backend with:

spin pipeline-template save --file ".../template-file.json"

The template such saved can be referred to instantiate pipelines by its id, and can be queried in the UI by its user-readable metadata.name.

To get the state of the template from the backend storage:

spin pipeline-template get --id "<pipeline-template-id>"

Once saved into the backend, the template can be used to instantiate pipelines, by generating the pipeline JSON. Note that this command does not store anything in the back end, it just generates the pipeline representation, it is our responsibility to take that representation and create the pipeline:

spin pipeline-template use --application "<application-name>" --id "<pipeline-template-id>" --name "<pipeline-name>" [--values "<.../values.yaml>"] > ~/tmp/my-pipeline.json

This command generates a JSON representation of the pipeline at stdout:

{
 "schema": "v2",
 "name": "some-pipeline",
 "application": "some-application",
 "template": {
  "reference": "spinnaker://my-template",
   [...]
 }
 "parameters": [],
 "variables": {},
  "stages": []
  [...]
}

The fact that is a pipeline instantiated from a template is obvious from the template.reference element, and the representation contains the application name and the pipeline name.

Discuss parameters and variables.

The JSON representation of the pipeline can be used to instantiate the pipeline with:

spin pipeline save --file "<pipeline-json-representation>"

Upon saving, the pipeline instance gets a unique ID.

The pipeline can be obtained from the backend with:

spin pipeline list --application "<application-name>"

or:

spin pipeline get --application"<application-name>"--name "<pipeline-name>"

Template

A template defines a parameterized pipeline, with the set of variables for which the users instantiating the template will provide values. The template does not have the pipeline configuration found on a pipeline instance. The template is useful in defining a pipeline pattern that can be instantiated as multiple concrete pipeline instances.

Template Example

https://spinnaker.io/docs/reference/pipeline/templates/

Pipeline template JSON example:

{
  "schema": "v2",
  "id": "my-pipeline-template",           # The pipeline instance references the template using this
  "protect": <true | false>,
  "metadata": {
    "name": "My Template Name as seen in the UI",
    "description": "<description>",
    "owner": "example@example.com",
    "scopes": ["global"]            # Not used
  },
  "variables": [
    {
      "name": "<varName>",
      "type": "<type>",
      "defaultValue": <value>,
      "description": "<description>"
    }
  ],
  "pipeline": {                     # Contains the templatized pipeline itself
    "lastModifiedBy": "anonymous",  # Not used
    "updateTs": "0",                # Not used
    "parameterConfig": [],          # Same as in a regular pipeline
    "limitConcurrent": true,        # Same as in a regular pipeline
    "keepWaitingPipelines": false,  # Same as in a regular pipeline
    "description": "",              # Same as in a regular pipeline
    "triggers": [],                 # Same as in a regular pipeline
    "notifications": [],            # Same as in a regular pipeline
    "stages": [                     # Contains the templated stages
      {
        # This one is an example stage:
        "waitTime": "${ templateVariables.waitTime }",  # Templated field.
        "name": "My Wait Stage",
        "type": "wait",
        "refId": "wait1",
        "requisiteStageRefIds": []
      }
    ]
  }
}

Elements

schema

id

The identifier of this template. The pipeline instances generated from this template will references the template using the value of id:

{
  [...]
  "template": {
    "artifactAccount": "...",
    "reference": "spinnaker://my-pipeline-template",
    "type": ".../pipelineTemplate"
  },
  [...]
}

The user readable name is given by metadata.name.

protect

'true' or 'false'

metadata

Metadata name

The name under which the template pipeline is listed in the UI. Note that while id is used to refer to the template while instantiating pipelines, the metadata.name is the "user readable" name.

scopes

Documentation says "not used" but an attempt save the pipeline template in the backend fails with "Missing required fields: metadata.scopes" if not present.

{
  "metadata": {
    "scopes": ["global"]
  }
}

variables

A template variable is a variable defined in a pipeline template's variables section , whose value is determined when a pipeline is instantiated based on the template. A template variable is different from a pipeline variable, which vary per execution of the pipeline. The template variables declared in the pipeline template can be referred, using their name, in the pipeline stages, as follows:

{
   "default": "${templateVariables.SomeVariableName}",
}

Variable name

Variable type

The type can be "string", ?

Variable defaultValue

Variable description

pipeline

The definition of the templatized pipeline.

parameterConfig

Same as in a regular pipeline.

stages

Contains the templatized stages.

keepWaitingPipelines

Same as in a regular pipeline. Default false.

limitConcurrent

Same as in a regular pipeline. Default true.

spelEvaluator

v4.

description

Same as in a regular pipeline.

triggers

Same as in a regular pipeline.

notifications

Same as in a regular pipeline.

lastModifiedBy

Not used.

updateTs

Not used.

Pipeline

A pipeline created from a template has a reference to the template it was created from, via the template id:

{
  [...]
  "template": {
    "reference": "spinnaker://my-pipeline-template",
   "type": ".../pipelineTemplate"
    "artifactAccount": "...",
  },
  [...]
}

Whether it’s created from a template or not, an executable pipeline that can be visualized in the UI.

Operations

Configuration

A pipeline template configuration is a concrete implementation of a template. Configurations can inject new stages into the final pipeline graph and inherit or override, or both, triggers, notifications, and parameters. The pipeline template configuration is the same as the configuration for a pipeline not created from a template, but it additionally has variable bindings and a reference to the template.