> For the complete CircleCI developer hub index, see [llms.txt](https://circleci.com/developer/llms.txt)

# christeredvartsen/persist-env

Persist environment variables between jobs.

## Commands

### persist-env

Persist all environment variables

### attach-env

Attach the environment variables previously stored

### set-env-var

Set an environment variable

| Parameter | Type | Default | Description |
|---|---|---|---|
| `var-name` | string |  | The name of the variable |
| `var-value` | string |  | The value of the variable |

## Examples

### set-env-var

Set an environment variable

```yaml
version: 2.1
orbs:
  env: christeredvartsen/persist-env@<version>
jobs:
  build:
    machine: true
    steps:
      - env/set-env-var:
          var-name: SOME_NAME
          var-value: some value
      - run: echo "Do some stuff with $SOME_NAME..."
```

### persist-env

Persist environment variables

```yaml
version: 2.1
orbs:
  env: christeredvartsen/persist-env@<version>
jobs:
  build:
    machine: true
    steps:
      - env/set-env-var:
          var-name: SOME_NAME
          var-value: some value
      - run: echo "Do some stuff with $SOME_NAME..."
      - env/persist-env
```

### attach-env

Attach environment variables set in a different job

```yaml
version: 2.1
orbs:
  env: christeredvartsen/persist-env@<version>
jobs:
  build:
    machine: true
    steps:
      - env/set-env-var:
          var-name: SOME_NAME
          var-value: some value
      - run: echo "Do some stuff..."
      - env/persist-env
  deploy:
    machine: true
    steps:
      - env/attach-env
      - run:
          name: Use env var set in build job
          command: echo $SOME_NAME
workflows:
  build-and-deploy:
    jobs:
      - build
      - deploy:
          requires:
            - build
```