# Set environment variables for each workflow in a stage

**URL:** <https://discuss.bitrise.io/t/set-environment-variables-for-each-workflow-in-a-stage/22414>\
**Category:** Pipelines\
**Created:** [March 22, 2023, 5:53pm UTC](https://discuss.bitrise.io/t/set-environment-variables-for-each-workflow-in-a-stage/22414 "2023-03-22T17:53:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![lukewakefordpassenge](https://avatars.discourse-cdn.com/v4/letter/l/ac91a4/32.png) [@lukewakefordpassenge](https://discuss.bitrise.io/u/lukewakefordpassenge)\
**Post date:** [March 22, 2023, 5:53pm UTC](https://discuss.bitrise.io/t/set-environment-variables-for-each-workflow-in-a-stage/22414/1 "2023-03-22T17:53:39Z")

</div>

Is it possible to set environment variables for a workflow within a stage? e.g.

```auto
stages:
  test:
    workflows:
    - all_tests: {}
  build:
    workflows:
    - single_scheme: {
      flavour: production
    }
    - single_scheme: {
      flavour: staging
    }

```

---

<div class="post-metadata">

**Author:** ![Leilah.squires](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/leilah.squires/32/4845_2.png) [@Leilah.squires](https://discuss.bitrise.io/u/Leilah.squires)\
**Post date:** [March 23, 2023, 3:17pm UTC](https://discuss.bitrise.io/t/set-environment-variables-for-each-workflow-in-a-stage/22414/2 "2023-03-23T15:17:09Z")

</div>

Hey @lukewakefordpassenge

Thanks for posting your question!

Yes, it is possible to set environment variables for a workflow within a stage.  
Add the following code to the bitrise.yml file:

```auto
format_version: 1.3.1
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git

stages:
  test:
    workflows:
      - all_tests: {}
  build:
    workflows:
      - single_scheme:
          flavour: production
      - single_scheme:
          flavour: staging

```

Next, add the environment variables to the workflows. For example:

```auto
format_version: 1.3.1
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git

stages:
  test:
    workflows:
      - all_tests:
          envs:
            - ENV_VAR_ONE: first value
            - ENV_VAR_TWO: second value
  build:
    workflows:
      - single_scheme:
          flavour: production
          envs:
            - ENV_VAR_ONE: first value
            - ENV_VAR_TWO: second value
      - single_scheme:
          flavour: staging
          envs:
            - ENV_VAR_ONE: first value
            - ENV_VAR_TWO: second value

```

Save the bitrise.yml file.

Run the bitrise command to execute the workflows:

```auto
bitrise run all_tests 
bitrise run single_scheme:production 
bitrise run single_scheme:staging

```

Please let us know if this helped or if you need further assistance.

Thanks again,  
Leilah

---

<div class="post-metadata">

**Author:** ![lukewakefordpassenge](https://avatars.discourse-cdn.com/v4/letter/l/ac91a4/32.png) [@lukewakefordpassenge](https://discuss.bitrise.io/u/lukewakefordpassenge)\
**Post date:** [March 23, 2023, 3:50pm UTC](https://discuss.bitrise.io/t/set-environment-variables-for-each-workflow-in-a-stage/22414/3 "2023-03-23T15:50:16Z")

</div>

Hey thanks for the pointers.

Is it possible to run the whole pipeline or an individual stage from the cli? e.g.

`bitrise run test` or `bitrise run build` ?

Right now these commands error with:

> specified Workflow (test) does not exist

---

<div class="post-metadata">

**Author:** ![Leilah.squires](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/leilah.squires/32/4845_2.png) [@Leilah.squires](https://discuss.bitrise.io/u/Leilah.squires)\
**Post date:** [March 23, 2023, 4:25pm UTC](https://discuss.bitrise.io/t/set-environment-variables-for-each-workflow-in-a-stage/22414/4 "2023-03-23T16:25:58Z")

</div>

Yes, it is possible to run the whole pipeline or an individual stage from the Bitrise CLI.

Typically to run an individual stage, you need to specify the **Workflow ID** in the bitrise run command: `bitrise run <WORKFLOWID>`

Before doing that though, can you make sure that the **Workflow ID** is correctly specified in the **bitrise.yml** file. The Workflow ID should match the ID of the Workflow you are trying to run.

Now to further troubleshoot the error:

1. Check the bitrise.yml file to make sure the Workflow with the name ‘test’ exists.

2. If the Workflow exists, check the configuration of the Workflow to make sure it is set up correctly. This includes checking the Step names, Step inputs, Step outputs, Environment Variables, and other configurations are correctly specified.

Please let me know if this was helpful or if you need additional assistance.

Thanks again,  
Leilah

---

<div class="post-metadata">

**Author:** ![ryanliszewski17](https://avatars.discourse-cdn.com/v4/letter/r/45deac/32.png) [@ryanliszewski17](https://discuss.bitrise.io/u/ryanliszewski17)\
**Post date:** [July 19, 2023, 12:05am UTC](https://discuss.bitrise.io/t/set-environment-variables-for-each-workflow-in-a-stage/22414/5 "2023-07-19T00:05:25Z")

</div>

This isn’t working for me when trying to add an env var to workflow in a stage. See an example of my `yaml` file here:

```auto
stages:
  install:
    workflows:
    - install_node_modules: {}
  build_platforms:
    workflows:
    - deploy_android_staging: {}
    - deploy_ios_staging:
        envs:
          - IOS_DISTRIBUTION_METHOD: ad-hoc

```

I’m also seeing a lint error as well when adding `envs` to a workflow in a stage. Any idea what’s going on here?

 ![Screen Shot 2023-07-19 at 8.05.04 AM](https://us1.discourse-cdn.com/flex016/uploads/bitrise/original/2X/6/611e59c00e19ac8459e57846988b9da0588c22e2.png)

---

<div class="post-metadata">

**Author:** ![pilvikala](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/pilvikala/32/4522_2.png) [@pilvikala](https://discuss.bitrise.io/u/pilvikala)\
**Post date:** [August 17, 2023, 12:56pm UTC](https://discuss.bitrise.io/t/set-environment-variables-for-each-workflow-in-a-stage/22414/6 "2023-08-17T12:56:46Z")

</div>

Hi! Specifying stage-specific environment variables on workflows in pipelines is currently not supported.

---

<div class="post-metadata">

**Author:** ![erickriseup](https://avatars.discourse-cdn.com/v4/letter/e/c37758/32.png) [@erickriseup](https://discuss.bitrise.io/u/erickriseup)\
**Post date:** [September 22, 2023, 10:37am UTC](https://discuss.bitrise.io/t/set-environment-variables-for-each-workflow-in-a-stage/22414/7 "2023-09-22T10:37:18Z")

</div>

Hello, currently I have my pipeline configured like this,  
However my env is never passed to the workflow. Is there any option? Or I should create all workflows differently?

I also have this issue when trying to add envs:  
 ![Screenshot 2023-09-22 at 11.36.55](https://us1.discourse-cdn.com/flex016/uploads/bitrise/original/2X/7/7cb002aee83077338a96abd6f335539735ff8883.png)

```auto
pipelines:
  pipeline-test-end-to-end:
    stages:
      - stage-build-end-to-end: {}
      - stage-test-end-to-end: {}

stages:
  stage-build-end-to-end:
    workflows:
      - workflow-build-e2e-android: {}
  stage-test-end-to-end:
    workflows:
      - workflow-test-e2e-android:
          envs:
            - TEST_TAG: tag-part-1
      - workflow-test-e2e-android:
          envs:
            - TEST_TAG: tag-part-2

```

---

<div class="post-metadata">

**Author:** ![erickriseup](https://avatars.discourse-cdn.com/v4/letter/e/c37758/32.png) [@erickriseup](https://discuss.bitrise.io/u/erickriseup)\
**Post date:** [September 22, 2023, 1:49pm UTC](https://discuss.bitrise.io/t/set-environment-variables-for-each-workflow-in-a-stage/22414/8 "2023-09-22T13:49:30Z")

</div>

[pilvikala](https://discuss.bitrise.io/u/pilvikala) Do you know if this feature will become available anytime soon? Thanks!

---

<div class="post-metadata">

**Author:** ![pilvikala](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/pilvikala/32/4522_2.png) [@pilvikala](https://discuss.bitrise.io/u/pilvikala)\
**Post date:** [October 11, 2023, 6:13pm UTC](https://discuss.bitrise.io/t/set-environment-variables-for-each-workflow-in-a-stage/22414/9 "2023-10-11T18:13:48Z")

</div>

@erickriseup Apologies, I am not with Bitrise anymore, so I don’t have that information.

@viktorbenei ?
