Skip to main content

Variables

Learn how to use environment variables in your pipelines.

Variables

Environment variables allow you to parameterize your pipeline configuration and pass values between stages.

Defining Variables

Pipeline Variables

Define variables at the pipeline level to make them available to all stages:

variables:
  NODE_ENV: production
  API_URL: https://api.example.com

stages:
  - name: build
    type: build
    config:
      buildArgs:
        NODE_ENV: $NODE_ENV
        API_URL: $API_URL

Stage Variables

Define variables for a specific stage:

stages:
  - name: test
    type: test
    config:
      image: node:18
      env:
        CI: 'true'
        TEST_TIMEOUT: '30000'
      commands:
        - npm test

Variable Types

Plain Text Variables

Standard environment variables visible in logs:

variables:
  LOG_LEVEL: debug
  MAX_RETRIES: '3'

Secret Variables

Secrets are encrypted and masked in logs:

secrets:
  DATABASE_URL:
    secretRef: db-connection-string
  API_KEY:
    secretRef: external-api-key

Built-in Variables

Sluice provides several built-in variables:

VariableDescriptionExample
SLUICE_PIPELINE_IDPipeline IDpipe_abc123
SLUICE_PIPELINE_NAMEPipeline namemy-pipeline
SLUICE_RUN_IDCurrent run IDrun_xyz789
SLUICE_VERSIONPipeline version5
SLUICE_STAGE_NAMECurrent stage namebuild
SLUICE_TRIGGERTrigger typewebhook

Git Variables

When triggered by a webhook:

VariableDescriptionExample
GIT_BRANCHBranch namemain
GIT_COMMITFull commit SHAabc123...
GIT_COMMIT_SHORTShort commit SHAabc123
GIT_TAGTag name (if applicable)v1.0.0
GIT_AUTHORCommit author[email protected]
GIT_MESSAGECommit messageFix bug in...

Variable Interpolation

Use variables in your configuration with different syntaxes:

Shell-style

config:
  image: $REGISTRY/$IMAGE_NAME
  tag: $VERSION

Template-style

config:
  image: '{{.Registry}}/{{.ImageName}}'
  tag: 'v{{.Version}}-{{.Commit}}'

Mixed

config:
  image: $REGISTRY/my-app
  tag: 'v{{.Version}}-$GIT_COMMIT_SHORT'

Variable Precedence

When the same variable is defined in multiple places, precedence is (highest to lowest):

  1. Run overrides - Variables set when triggering a run
  2. Stage variables - Variables defined in the stage config
  3. Pipeline variables - Variables defined at the pipeline level
  4. Built-in variables - Sluice-provided variables
  5. Default values - Defaults specified in variable definitions

Default Values

Specify default values for optional variables:

variables:
  LOG_LEVEL:
    default: info
  REPLICAS:
    default: '2'

Conditional Variables

Set variables based on conditions:

variables:
  ENVIRONMENT:
    value: production
    condition: "branch == 'main'"
  ENVIRONMENT:
    value: staging
    condition: "branch == 'develop'"
  ENVIRONMENT:
    default: development

Passing Variables Between Stages

Use outputs to pass values from one stage to another:

stages:
  - name: build
    type: build
    config:
      # ...
    outputs:
      IMAGE_DIGEST: $DOCKER_IMAGE_DIGEST

  - name: deploy
    type: deploy
    config:
      image: my-app@$IMAGE_DIGEST

Best Practices

  1. Use secrets for sensitive data - Never put passwords, API keys, or tokens in plain variables
  2. Provide defaults - Define sensible defaults for optional variables
  3. Use descriptive names - DATABASE_URL is clearer than DB
  4. Document variables - Add comments explaining what each variable is for
  5. Validate inputs - Check that required variables are set before using them

Next Steps