Platform Vars
Example Starlark template with platform vars.
We recommend reviewing Starlark Spec before attempting to create a template.
Additionally, depending on how the template is written, it may be incompatible with viewing pipelines in the UI.
Overview
Platform variables can be referenced with the following syntax:
ctx['vela']['<resource>']['<name>']
Examples
ctx["vela"]["repo"]["name"]
equates to theVELA_REPO_NAME
environment variablectx["vela"]["build"]["number"]
equates to theVELA_BUILD_NUMBER
environment variablectx["vela"]["system"]["addr"]
equates to theVELA_ADDR
environment variablectx["vela"]["deployment"]["<name>"]
equates to theDEPLOYMENT_PARAMETER_<name>
environment variable
Sample
Let’s take a look at using a platform variable within a template:
def main(ctx):
return {
'version': '1',
'steps': [
step(ctx["vela"]["repo"]["name"]),
],
}
def step(name):
return {
"name": "echo %s" % name,
"image": "alpine:latest",
'commands': [
"echo %s" % name
]
}
The caller of this template could look like:
version: "1"
templates:
- name: sample
source: github.com/<org>/<repo>/path/to/file/<template>.star
format: starlark
type: github
steps:
- name: build
template:
name: sample
Which means the compiled pipeline for execution on a worker is:
version: 1
steps:
- name: sample_echo hello-world
image: alpine:latest
commands:
- echo hello-world
Last modified December 13, 2022: enhance(templates): add deployment parameter details (#306) (e58dd418)