Environment Variables

You can set environment variables in task definitions by specifying the env key. Tasks can also set environment variables as outputs which will take effect when including the task in a use definition of another task.

Setting Environment Variables

tasks:
  - key: example-with-env
    run: echo hello $NAME
    env:
      NAME: world

Cache

You can exclude an environment variable from the cache key for a task. This is commonly used for ephemeral authentication credentials that would result in always having a cache miss if they weren't excluded.

tasks:
  - key: aws-example
    run: |
      # something with the aws cli
      aws ...
    env:
      AWS_ACCESS_KEY_ID:
        value: ${{ secrets.AWS_ACCESS_KEY_ID }}
        cache: false
      AWS_SECRET_ACCESS_KEY:
        value: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        cache: false

Environment Variable Outputs

Tasks can also output environment variables by writing a file to the $MINT_ENV directory. The file name will be treated as the environment variable name, and its value will be the environment variable value. Environment variables written to that file will automatically be set for other tasks with a use dependency.

tasks:
  - key: set-env-one
    run: echo hello > $MINT_ENV/ONE
  - key: set-env-two
    run: echo world >> $MINT_ENV/TWO
  - key: print-env
    use: [set-env-one, set-env-two]
    run: |
      echo $ONE $TWO
      env | grep -E 'ONE|TWO'

The print-env task will output:

hello world
ONE=hello
TWO=world

Merging

By default, if multiple tasks set an environment variable, the task is specified last in the use declaration will overwrite previous values. However, you may want to combine the values. A common use case for this is having multiple tasks which will append to the $PATH environment variable. Mint automatically merges $PATH by default, so this will work:

tasks:
  - key: path-one
    run: |
      mkdir one
      echo "echo script one" > one/one.sh
      chmod +x one/one.sh
      echo "PATH=$PWD/one" >> $MINT_ENV
  - key: path-two
    run: |
      mkdir two
      echo "echo script two" > two/two.sh
      chmod +x two/two.sh
      echo "PATH=$PWD/two" >> $MINT_ENV
  - key: use-one-and-two
    use: [path-one, path-two]
    run: |
      echo $PATH
      one.sh
      two.sh

The use-one-and-two task will output:

/var/mint-workspace/two:/var/mint-workspace/one:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
script one
script two

It's rare to need to combine environment variable updates like this, but if you do, you can specify an env-config on your task definition which will determine how environment variables set by use dependencies are applied. The default behavior for $PATH is actually the following env-config.

- key: use-one-and-two
  use: [path-one, path-two]
  run: |
    echo $PATH
    one.sh
    two.sh
  env-config:
    merge:
      PATH:
        strategy: join
        by: ':'