# Secrets and environment variables

**URL:** <https://discuss.bitrise.io/t/secrets-and-environment-variables/10940>\
**Category:** Question & Answer\
**Created:** [November 12, 2019, 5:07pm UTC](https://discuss.bitrise.io/t/secrets-and-environment-variables/10940 "2019-11-12T17:07:24Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![bdaniels](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/bdaniels/32/2588_2.png) [@bdaniels](https://discuss.bitrise.io/u/bdaniels)\
**Post date:** [November 12, 2019, 5:07pm UTC](https://discuss.bitrise.io/t/secrets-and-environment-variables/10940/1 "2019-11-12T17:07:24Z")

</div>

This question relates to the secrets and env vars tabs. I am trying to avoid using scripts with envman.

First off, why can’t you set secrets for different workflows like you can environment vars? What if I have a different secret key for each environment I need to build for?

Second, starting to play with Secrets and Env Vars and I have a few usage questions which I could not find documented.

1. Can Secrets reference Env Vars such as:

- AUTH\_ISSUER=$SSO\_URL

1. Can Env Vars reference other Env Vars such as:

- MY\_BUILD\_NUM=$BITRISE\_BUILD\_NUM
- ENVIRONMENT\_NAME=nightly
- BASE\_URL=${ENVIRONMENT\_NAME}.company.com
- API\_URL=https://api-${BASE\_URL}

1. Can Env Vars reference Secrets such as:  
(This seems necessary because secrets can’t be split up based on workflow)

- Secrets:  
NIGHTLY\_API\_KEY=123  
PROD\_API\_KEY=456
- Env Vars:  
Nightly Workflow:  
API\_KEY=$NIGHTLY\_API\_KEY  
Prod Workflow:  
API\_KEY=$PROD\_API\_KEY

---

<div class="post-metadata">

**Author:** ![koral](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/koral/32/357_2.png) [@koral](https://discuss.bitrise.io/u/koral)\
**Post date:** [November 12, 2019, 6:36pm UTC](https://discuss.bitrise.io/t/secrets-and-environment-variables/10940/2 "2019-11-12T18:36:57Z")

</div>

Look here: [https://devcenter.bitrise.io/bitrise-cli/most-important-concepts/#availability-order-of-environment-variables](https://devcenter.bitrise.io/bitrise-cli/most-important-concepts/#availability-order-of-environment-variables)

---

<div class="post-metadata">

**Author:** ![bdaniels](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/bdaniels/32/2588_2.png) [@bdaniels](https://discuss.bitrise.io/u/bdaniels)\
**Post date:** [November 12, 2019, 7:09pm UTC](https://discuss.bitrise.io/t/secrets-and-environment-variables/10940/3 "2019-11-12T19:09:05Z")

</div>

ok so

1. Can Secrets reference Env Vars:

> In the value of a `Secret` Environment Variable, you can use Environment Variables exposed by Bitrise CLI, but you can’t use any other Environment Variable (App Env Vars, Workflow Env Vars, and so on), as those are not processed when Secrets are processed.

1. Can Env Vars reference other Env Vars:

> In the value of an `App Env Var` , you can use environment variables from `Secrets` as well as the Bitrise CLI exposed ones, but you can’t use Workflow Env Vars or Step inputs

1. Can Env Vars reference Secrets:

> In a `Workflow environment variable` you can use all the above ( `Secrets` , `App Env Vars` , Bitrise CLI exposed env vars).

These seem to answer my questions, although now new questions arise:

1. How do you “use” other variables? I didn’t see any syntax examples. Are the following acceptable?  
MY\_BUILD\_NUM=$BITRISE\_BUILD\_NUM  
API\_URL=“[https://api-$](https://api-$){BASE\_URL}”

2. I read this:

> If the workflow has workflows [chained before or after it](https://devcenter.bitrise.io/getting-started/getting-started-workflows/#chaining-workflows-together), the environment variables of the chained workflows are processed and made available right before the first step of the workflow would run.

If I have a generic `setup` workflow, and then I have environment specific `build` workflows. Can the `setup` workflow depend on workflow specific environment variables being set before the `setup` workflow is ran. This wasn’t entirely clear to me based on the above statement.

---

<div class="post-metadata">

**Author:** ![koral](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/koral/32/357_2.png) [@koral](https://discuss.bitrise.io/u/koral)\
**Post date:** [November 19, 2019, 5:19pm UTC](https://discuss.bitrise.io/t/secrets-and-environment-variables/10940/4 "2019-11-19T17:19:22Z")

</div>

> [@bdaniels](#):
>
> How do you “use” other variables? I didn’t see any syntax examples. Are the following acceptable?  
> MY\_BUILD\_NUM=$BITRISE\_BUILD\_NUM  
> API\_URL=“[https://api-$](https://api-%24){BASE\_URL}”

Correct, both should be acceptable.  
Keep in mind that variable can only be used in input if its `is_expand` property is set to true.

> [@bdaniels](#):
>
> Can the `setup` workflow depend on workflow specific environment variables being set before the `setup` workflow is ran.

Not sure if I understand correctly, but it should be possible. If variable is exported before then it should be available in later stages.

---

<div class="post-metadata">

**Author:** ![bdaniels](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/bdaniels/32/2588_2.png) [@bdaniels](https://discuss.bitrise.io/u/bdaniels)\
**Post date:** [November 19, 2019, 6:02pm UTC](https://discuss.bitrise.io/t/secrets-and-environment-variables/10940/5 "2019-11-19T18:02:32Z")

</div>

Regarding the chained workflows, the setup workflow is using workflow environment variables that are set on the build- workflow it is chained to which is good news.

As far as is\_expand, “Replace variables in Inputs”, and “Expose for pull requests”, I guess I don’t really understand those concepts yet.

---

<div class="post-metadata">

**Author:** ![koral](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/koral/32/357_2.png) [@koral](https://discuss.bitrise.io/u/koral)\
**Post date:** [November 19, 2019, 11:49pm UTC](https://discuss.bitrise.io/t/secrets-and-environment-variables/10940/6 "2019-11-19T23:49:31Z")

</div>

> [@bdaniels](#):
>
> As far as is\_expand, “Replace variables in Inputs”

If flag is true then variables in inputs are evaluated by CLI before executing the step eg. `$CI` will be evaluated to either `"true"` or `"false"`. OTOH if flag is false then nothing is evaluated and `$CI` stays `"$CI"`.

> [@bdaniels](#):
>
> Expose for pull requests

If it is disabled then variable won’t exist in PR builds.

---

<div class="post-metadata">

**Author:** ![bdaniels](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/bdaniels/32/2588_2.png) [@bdaniels](https://discuss.bitrise.io/u/bdaniels)\
**Post date:** [November 20, 2019, 4:18pm UTC](https://discuss.bitrise.io/t/secrets-and-environment-variables/10940/7 "2019-11-20T16:18:25Z")

</div>

According to the documentation:

> The **Expose for Pull Request** toggle can be enabled if you want your secrets to be exposed in your build logs in pull requests.

Does this mean they won’t show up in the build logs or they just aren’t available at all?

I’ve been having builds start to fail that are triggered by PRs, and the logs don’t seem to indicate why. I recently started storing auth related values in the secrets.

---

<div class="post-metadata">

**Author:** ![koral](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/koral/32/357_2.png) [@koral](https://discuss.bitrise.io/u/koral)\
**Post date:** [November 20, 2019, 4:40pm UTC](https://discuss.bitrise.io/t/secrets-and-environment-variables/10940/8 "2019-11-20T16:40:16Z")

</div>

> [@bdaniels](#):
>
> Does this mean they won’t show up in the build logs or they just aren’t available at all?

They won’t be available at all.

---

<div class="post-metadata">

**Author:** ![bdaniels](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/bdaniels/32/2588_2.png) [@bdaniels](https://discuss.bitrise.io/u/bdaniels)\
**Post date:** [November 20, 2019, 8:51pm UTC](https://discuss.bitrise.io/t/secrets-and-environment-variables/10940/9 "2019-11-20T20:51:38Z")

</div>

Great thanks for all your help!

---

<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:** [December 20, 2019, 8:51pm UTC](https://discuss.bitrise.io/t/secrets-and-environment-variables/10940/10 "2019-12-20T20:51:41Z")

</div>

Closed on December 20, 2019, 8:51pm UTC

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