Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Masaori-Hirono · Dec 13, 2018 at 02:53 AM · unity cloud build

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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DevinT7 · Jan 11, 2019 at 06:57 AM 0
Share

I’ve actually been trying to figure out how to do this myself. Unity does support environment variables but only through the cloud build API and not the GUI at this time. You can find the API docs here https://build-api.cloud.unity3d.com/docs/1.0.0/index.html let me know if you figure out how to use the variables at build time. I’m still trying to wrap my head around all this myself.

1 Reply

· Add your reply
  • Sort: 
avatar image
8

Answer by DevinT7 · Jan 15, 2019 at 11:25 PM

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 https://developer.cloud.unity3d.com/build/orgs/{ORGID}/projects/{PROJECTID}/setup/buildtarget/{BUILDTARGETID}


Example: https://developer.cloud.unity3d.com/build/orgs/my-fake-org/projects/my-cool-project/setup/buildtarget/android-example-config/ 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

 #if UNITY_CLOUD_BUILD

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");
 AssetDatabase.SaveAssets();

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

102 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

[Unity Cloud Build] Fatal Error! The file 'none' is corrupted! 0 Answers

iOS Unity Cloud Build failed when 'Target minimum iOS version' is set to 9 0 Answers

UnityCloudBuildProjectId not set in info.plist (iOS) 0 Answers

Unity Cloud Build bug at Visual Studio Team Services 1 Answer

Get Unity Cloud Build Index 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges