Is there any way to set Environment Variables to Cloud Build?

Hi, folks.

I use Cloud Build to build my own project.
And I want to load some confidential informations such like Access Token for external services from build scripts.
To avoid committing them into source code, I’m looking for a way to refer Env Variables during build but I haven’t got yet.

There doesn’t seem to be any UIs where I can set them in Cloud Build web console.

Do anybody know any solutions for this?
Thanks in advance.

Hey! So i Just went through this process myself.

Environment variables are supported by Unity Cloud Build but not through their GUI. Using them isn’t the most straight forward process. To set and environment variable for a specific build config you need to use the Unity Cloud Build API . You can setup your variables directly through this UI, set your API key in the top left you can find your key Here.

Then just CTRL-F “Environment Variable”.

You can find your ORGID, PROJECTID, and BUILDTARGETID as follows: If you have your config selected in the unity cloud build dashboard all your info will be in the URL Unity ID

Example: Unity ID Here my ORGID would be my-fake-org my PROJECTID would be my-cool-project and build target would be android-example-config

After setting your Environment Variables you can access them at build time via

var myVar = Environment.GetEnvironmentVariable("MY_ENV_VARIABLE"); 

In your pre-export method.

As a side note, if you have any methods you only want cloud build ever to look at and use then wrap them in


The best method I’ve found to use an environment variable or save data to a build is to just record it as a scriptable object which is created at build time and saved to Resources.

Instrument.AppDataContainer asset = ScriptableObject.CreateInstance<Instrument.AppDataContainer>();

asset.envVariable = myVar;

AssetDatabase.CreateAsset(asset, "Assets/Resources/ApplicationConfigData.asset");

Where AppDataContainer is a scriptable asset that just receives strings of data

Hopefully this helps, I went through a lot of rounds where I was close to pulling my hair out looking for documentation on this.