Setting Environment Variables#

Semaphore supports setting environment variables for an individual job, for all jobs in a block, and for all jobs in a pipeline.

If you're looking for a list of environment variables which Semaphore sets in every job, refer to the CI/CD Environment guide.

Using Workflow Builder#

To set a new environment variable:

  1. Open Workflow Builder.
  2. Select a block or job to which you would like to export environment variables.
  3. Click Environment variables.
  4. Click Add env vars.
  5. Fill in the variable's key and value.
  6. Optionally, add more variables.
  7. Click Run the workflow to save your configuration and run a new workflow.

YAML example#

Here's an example which applies an environment variable to all jobs in the block:

# .semaphore/semaphore.yml
blocks:
  - name: "Test"
    task:
      env_vars:
        - name: GUIDED_TOUR
          value: "TRUE"
      jobs:
        - name: Lint
          commands:
            - echo "${GUIDED_TOUR}"
            - echo 'Linting code'
        - name: Unit
          commands:
            - echo "${GUIDED_TOUR}"
            - echo 'Unit tests'

Note: Numeric values need to be included in quotes.