# Overriding env of previous workflow/reading env of next workflow

**URL:** <https://discuss.bitrise.io/t/overriding-env-of-previous-workflow-reading-env-of-next-workflow/8858>\
**Category:** Question & Answer\
**Tags:** fastlane, ios, workflow, environment-variable\
**Created:** [April 25, 2019, 7:52am UTC](https://discuss.bitrise.io/t/overriding-env-of-previous-workflow-reading-env-of-next-workflow/8858 "2019-04-25T07:52:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![arkus](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/arkus/32/2231_2.png) [@arkus](https://discuss.bitrise.io/u/arkus)\
**Post date:** [April 25, 2019, 7:52am UTC](https://discuss.bitrise.io/t/overriding-env-of-previous-workflow-reading-env-of-next-workflow/8858/1 "2019-04-25T07:52:12Z")

</div>

Hi,

I’ve been trying to create separate workflows for:

- building staging app
- building production app
- deploying staging app to Fabric Beta (using build staging workflow)
- deploying staging app to TestFlight (using build staging workflow)
- deploying production app to Fabric Beta (using build production workflow)
- deploying production app to TestFlight (using build production workflow)

As the Fabric wants AdHoc provisioning profile and we use AppStore provisioning profile for TestFlight, I’ve created separate lanes to build the app for fabric (adhoc) and test flight (appstore).

I’ve come up with an idea I’d create separate workflows like this:

- build-staging
- build-production
- deploy-fabric-staging
- deploy-fabric-production
- deploy-appstore-staging
- deploy-appstore-production

The `build-*` workflows have the ENV variable `FASTLANE_BUILD_LANE` where I’ve put lane with params for specific app stage.  
What I’ve wanted to achieve is when I run build for one of the `deploy-*` workflows, it would change the value of `FASTLANE_BUILD_LANE` env, so it builds the app in the previous workflow correctly.  
So I’ve put different values for this env in the settings of these workflows.

Unfortunately, this doesn’t work as I expected, as it uses the env defined within `build-*` workflow instead of the next one (`deploy-*`).

Is there a way to achieve what I’m trying to do without creating multiple workflows for building the app?Example:

- `build-staging-fabric`,
- `build-production-fabric`,
- `build-staging-appstore`,
- `build-production-appstore`

Is there another way to override env value of previous step in workflows or read env value of next step?

---

<div class="post-metadata">

**Author:** ![fehersanyi-bitrise](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/fehersanyi-bitrise/32/1912_2.png) [@fehersanyi-bitrise](https://discuss.bitrise.io/u/fehersanyi-bitrise)\
**Post date:** [April 25, 2019, 8:34am UTC](https://discuss.bitrise.io/t/overriding-env-of-previous-workflow-reading-env-of-next-workflow/8858/2 "2019-04-25T08:34:07Z")

</div>

Hy @arkus

If this would be a constant then I would add a script at the beggining of the deploy wokrflows with a content like this:

```auto
echo $FASTLANE_BUILD_LANE
echo "Overriding variable"
envman add --key FASTLANE_BUILD_LANE --value "your-deploy-lane"
echo "Done"

```

the strange part will be that if you would echo FASTLANE\_BUILD\_LANE in this step it would give you the old variable, but in the next step it would be the new one, like this:

 ![11](https://us1.discourse-cdn.com/flex016/uploads/bitrise/original/2X/2/219fc09e958560c788be36cfdd3f68da5373cabc.png)

---

<div class="post-metadata">

**Author:** ![arkus](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/arkus/32/2231_2.png) [@arkus](https://discuss.bitrise.io/u/arkus)\
**Post date:** [April 25, 2019, 8:58am UTC](https://discuss.bitrise.io/t/overriding-env-of-previous-workflow-reading-env-of-next-workflow/8858/3 "2019-04-25T08:58:58Z")

</div>

@fehersanyi-bitrise  
Ok, so just to be sure I’ve understood you, I should put additional step within deploy workflow to set the variable value to the desired build lane for that workflow, right?

What will happen when the `build*` workflow has the env value set in the `Env Vars` section?  
Won’t it override the value set in the script from step 1?

---

<div class="post-metadata">

**Author:** ![fehersanyi-bitrise](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/fehersanyi-bitrise/32/1912_2.png) [@fehersanyi-bitrise](https://discuss.bitrise.io/u/fehersanyi-bitrise)\
**Post date:** [April 25, 2019, 9:08am UTC](https://discuss.bitrise.io/t/overriding-env-of-previous-workflow-reading-env-of-next-workflow/8858/4 "2019-04-25T09:08:20Z")

</div>

@arkus that is exactly what I meant 🙃  
the script will only override the env as long as the build runs with this method🤔  
in this example I screen shotted, TEST\_VAR is set on the env var tab, in the first script I echo it so we see that ![itssomething](https://us1.discourse-cdn.com/flex016/uploads/bitrise/original/2X/d/d678d244402937c880955315351b7c3ff954c110.jpeg)  
then I changed with the envman tool to the other thing, and from that point in that build it will be that.

---

<div class="post-metadata">

**Author:** ![arkus](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/arkus/32/2231_2.png) [@arkus](https://discuss.bitrise.io/u/arkus)\
**Post date:** [April 25, 2019, 9:18am UTC](https://discuss.bitrise.io/t/overriding-env-of-previous-workflow-reading-env-of-next-workflow/8858/5 "2019-04-25T09:18:25Z")

</div>

The issue here is that I can’t add one step before the whole workflow.  
What I mean is that my deployment workflow uses build workflow as the previous workflow, so it looks e.g. like this: `build-staging -> deploy-staging-fabric`

When I’m in the workflow editor I cannot add just step before the `build-staging` workflow, I’d need to add another workflow to setup this, so I think it would be the same issue 🤔

---

<div class="post-metadata">

**Author:** ![fehersanyi-bitrise](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/fehersanyi-bitrise/32/1912_2.png) [@fehersanyi-bitrise](https://discuss.bitrise.io/u/fehersanyi-bitrise)\
**Post date:** [April 25, 2019, 9:56am UTC](https://discuss.bitrise.io/t/overriding-env-of-previous-workflow-reading-env-of-next-workflow/8858/6 "2019-04-25T09:56:18Z")

</div>

Oh I understand the issue, I was misunderstanding it,  
what is the difference between build staging and build production?  
is it only the branch? or are there any extra steps?

---

<div class="post-metadata">

**Author:** ![arkus](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/arkus/32/2231_2.png) [@arkus](https://discuss.bitrise.io/u/arkus)\
**Post date:** [April 25, 2019, 10:03am UTC](https://discuss.bitrise.io/t/overriding-env-of-previous-workflow-reading-env-of-next-workflow/8858/7 "2019-04-25T10:03:08Z")

</div>

The main difference is the app scheme chosen to build with fastlane (so different params for the build lane) and different trigger branch.

---

<div class="post-metadata">

**Author:** ![fehersanyi-bitrise](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/fehersanyi-bitrise/32/1912_2.png) [@fehersanyi-bitrise](https://discuss.bitrise.io/u/fehersanyi-bitrise)\
**Post date:** [April 25, 2019, 10:06am UTC](https://discuss.bitrise.io/t/overriding-env-of-previous-workflow-reading-env-of-next-workflow/8858/8 "2019-04-25T10:06:05Z")

</div>

maybe the best approach would be to have one build workflow, 2 deploy workflows, and four empty ones called

- `build-staging-fabric` ,
- `build-production-fabric` ,
- `build-staging-appstore` ,
- `build-production-appstore`

so 6 total, and chaining them after one another like you do now, and use workflow specific env vars 🤔  
so this way you don’t really make duplicates but can set up the 4 way separately

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/bitrise/original/2X/d/d901cf2aad020f2dd11918afc89ec2089bb87b35.png) [@system](https://discuss.bitrise.io/u/system)\
**Post date:** [May 25, 2019, 10:06am UTC](https://discuss.bitrise.io/t/overriding-env-of-previous-workflow-reading-env-of-next-workflow/8858/9 "2019-05-25T10:06:07Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
