{"_id":"590a04f6ed80861900cbc784","category":{"_id":"590a04f3ed80861900cbc73f","version":"590a04f2ed80861900cbc737","project":"55b2d5baa74a380d00e290c4","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-10-02T17:55:17.903Z","from_sync":false,"order":7,"slug":"builds-and-tests","title":"Builds"},"parentDoc":null,"user":"55b2d5626862a10d00887af9","__v":0,"project":"55b2d5baa74a380d00e290c4","version":{"_id":"590a04f2ed80861900cbc737","project":"55b2d5baa74a380d00e290c4","__v":4,"createdAt":"2017-05-03T16:27:30.085Z","releaseDate":"2017-05-03T16:27:30.085Z","categories":["590a04f3ed80861900cbc738","590a04f3ed80861900cbc739","590a04f3ed80861900cbc73a","590a04f3ed80861900cbc73b","590a04f3ed80861900cbc73c","590a04f3ed80861900cbc73d","590a04f3ed80861900cbc73e","590a04f3ed80861900cbc73f","590a04f3ed80861900cbc740","590a04f3ed80861900cbc741","590a04f3ed80861900cbc742","590a04f3ed80861900cbc743","590a04f3ed80861900cbc744","590a04f3ed80861900cbc745","590a04f3ed80861900cbc746","590a04f3ed80861900cbc747","590a04f3ed80861900cbc748","590a04f3ed80861900cbc749","590a04f3ed80861900cbc74a","590a04f3ed80861900cbc74b","590a04f3ed80861900cbc74c","590a04f3ed80861900cbc74d","59124949de13f61900336a7a","5914b04e7c2c552d008b7104","5914b47242c6a22300b9dc20"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"7.0.0","version":"7"},"updates":["56baa2928fce0e1900d9935a"],"next":{"pages":[],"description":""},"createdAt":"2015-12-02T00:00:32.479Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":3,"body":"You might have API keys and other secrets that your app needs to consume - either at runtime or during a build. However, you might not want to check these secrets into your source code to make them available to your app.\n\nIn order to securely propagate your credentials to your build and app, buddybuild provides two sets of variables that you can define: \n\n1. [Environment Variables](/docs/environment-variables#section-step-1-create-environment-variables-in-buddybuild) (made available to your build time scripts, more details at [Custom Build Steps](doc:custom-prebuild-and-postbuild-steps))\n2. [Device Variables](/docs/device-variables-1#section-step-1-create-device-variables-in-buddybuild) (available your App at runtime via the buddybuild SDK)\n3. [Secure Files](doc:secure-files) (files made available to your build time scripts)\n\n\nYou can create default Environment Variables, which are available to all branches, or branch-specific environment variables which are only available for a specific branch.\n[block:api-header]\n{\n  \"title\": \"Creating default environment variables\"\n}\n[/block]\nStart by clicking on **App Settings**.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/ce12ba7-Builds_-_Settings.png\",\n        \"Builds - Settings.png\",\n        1500,\n        483,\n        \"#ecf1f2\"\n      ],\n      \"sizing\": \"full\"\n    }\n  ]\n}\n[/block]\nIn the left navigation, select **Build settings**, then the **Environment** tab.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/16b4731-Settings_-_Environment_variables_-_menu.png\",\n        \"Settings - Environment variables - menu.png\",\n        1500,\n        459,\n        \"#e6ecec\"\n      ],\n      \"sizing\": \"full\"\n    }\n  ]\n}\n[/block]\nIn the Environment variables row, click **Configure**.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/e70e6be-Settings_-_Environment_variables_-_configure.png\",\n        \"Settings - Environment variables - configure.png\",\n        1500,\n        691,\n        \"#d7dee1\"\n      ]\n    }\n  ]\n}\n[/block]\nEnter a name and value to create a default environment variable. Your environment variable is now ready to be consumed by your app at build time.\n\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/b9fcf0c-Settings_-_Environment_variables.png\",\n        \"Settings - Environment variables.png\",\n        1500,\n        760,\n        \"#e8eff1\"\n      ],\n      \"sizing\": \"full\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Create environment variables for a specific branch\"\n}\n[/block]\nYou can also create environment variables for a specific branch by creating a **branch-specific override**.\n\nUnder Override build configuration, click **Add a branch** and select the branch you would like to create an environment variable for.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/bed3901-Settings_-_Variants_-_Branch-specific-1.png\",\n        \"Settings - Variants - Branch-specific-1.png\",\n        1500,\n        555,\n        \"#d4dde2\"\n      ]\n    }\n  ]\n}\n[/block]\nSelect **Environment variables** from the dropdown and click **Configure**.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/62a1df4-Settings_-_Environment_variables_-_Branch_-_configure.png\",\n        \"Settings - Environment variables - Branch - configure.png\",\n        1500,\n        540,\n        \"#1294e1\"\n      ]\n    }\n  ]\n}\n[/block]\nEnter a name and value to create your branch-specific environment variable.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/9209073-Settings_-_Environment_variables_-_Branch_-_create.png\",\n        \"Settings - Environment variables - Branch - create.png\",\n        1500,\n        760,\n        \"#e9f1f3\"\n      ]\n    }\n  ]\n}\n[/block]\n## Consume the variable in your build\n\nYour environment variables will be automatically consumed by tools that are expecting them. \n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"<a href=\\\"#section-2a-consume-in-your-custom-build-scripts-\\\">2a. Consume in your custom build scripts.</a>\\n<a href=\\\"#section-2b-consume-in-android-build-gradle-file-\\\">2b. Consume in Android build.gradle file.</a>\"\n}\n[/block]\n## 2a. Consume in your custom build scripts.\nIf you would like to access them in your [custom build scripts](doc:custom-prebuild-and-postbuild-steps), use the bash variable expansion syntax.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"./Example.framework/run $Crashlytics_Token\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n## 2b. Consume in Android build.gradle file.\n\nIf you are building an **Android** app with **Gradle** (Android Studio), you can also access them 2 ways inside your **build.gradle** file\n\nYou can access them via **System.getenv()**, like this:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"buildscript {\\n\\trepositories {\\n\\t\\tjcenter()\\n  \\tmaven {\\n\\t\\t\\tcredentials {\\n        username System.getenv(\\\"ARTIFACTORY_USERNAME\\\")\\n        password System.getenv(\\\"ARTIFACTORY_PASSWORD\\\")\\n      }\\n      url System.getenv(\\\"ARTIFACTORY_URL\\\")\\n\\t\\t}\\n\\t}\\n\\t...\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nWe also put these variables inside **gradle.properties** file, so you can access them directly like:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"buildscript {\\n\\trepositories {\\n\\t\\tjcenter()\\n  \\tmaven {\\n\\t\\t\\tcredentials {\\n        username ARTIFACTORY_USERNAME\\n        password ARTIFACTORY_PASSWORD\\n      }\\n      url ARTIFACTORY_URL\\n\\t\\t}\\n\\t}\\n\\t...\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nThat's it! If you want to consume your variables from within your app, follow the [Device Variables](/docs/device-variables-1) guide.","excerpt":"","slug":"environment-variables","type":"basic","title":"Environment Variables"}

Environment Variables


You might have API keys and other secrets that your app needs to consume - either at runtime or during a build. However, you might not want to check these secrets into your source code to make them available to your app. In order to securely propagate your credentials to your build and app, buddybuild provides two sets of variables that you can define: 1. [Environment Variables](/docs/environment-variables#section-step-1-create-environment-variables-in-buddybuild) (made available to your build time scripts, more details at [Custom Build Steps](doc:custom-prebuild-and-postbuild-steps)) 2. [Device Variables](/docs/device-variables-1#section-step-1-create-device-variables-in-buddybuild) (available your App at runtime via the buddybuild SDK) 3. [Secure Files](doc:secure-files) (files made available to your build time scripts) You can create default Environment Variables, which are available to all branches, or branch-specific environment variables which are only available for a specific branch. [block:api-header] { "title": "Creating default environment variables" } [/block] Start by clicking on **App Settings**. [block:image] { "images": [ { "image": [ "https://files.readme.io/ce12ba7-Builds_-_Settings.png", "Builds - Settings.png", 1500, 483, "#ecf1f2" ], "sizing": "full" } ] } [/block] In the left navigation, select **Build settings**, then the **Environment** tab. [block:image] { "images": [ { "image": [ "https://files.readme.io/16b4731-Settings_-_Environment_variables_-_menu.png", "Settings - Environment variables - menu.png", 1500, 459, "#e6ecec" ], "sizing": "full" } ] } [/block] In the Environment variables row, click **Configure**. [block:image] { "images": [ { "image": [ "https://files.readme.io/e70e6be-Settings_-_Environment_variables_-_configure.png", "Settings - Environment variables - configure.png", 1500, 691, "#d7dee1" ] } ] } [/block] Enter a name and value to create a default environment variable. Your environment variable is now ready to be consumed by your app at build time. [block:image] { "images": [ { "image": [ "https://files.readme.io/b9fcf0c-Settings_-_Environment_variables.png", "Settings - Environment variables.png", 1500, 760, "#e8eff1" ], "sizing": "full" } ] } [/block] [block:api-header] { "title": "Create environment variables for a specific branch" } [/block] You can also create environment variables for a specific branch by creating a **branch-specific override**. Under Override build configuration, click **Add a branch** and select the branch you would like to create an environment variable for. [block:image] { "images": [ { "image": [ "https://files.readme.io/bed3901-Settings_-_Variants_-_Branch-specific-1.png", "Settings - Variants - Branch-specific-1.png", 1500, 555, "#d4dde2" ] } ] } [/block] Select **Environment variables** from the dropdown and click **Configure**. [block:image] { "images": [ { "image": [ "https://files.readme.io/62a1df4-Settings_-_Environment_variables_-_Branch_-_configure.png", "Settings - Environment variables - Branch - configure.png", 1500, 540, "#1294e1" ] } ] } [/block] Enter a name and value to create your branch-specific environment variable. [block:image] { "images": [ { "image": [ "https://files.readme.io/9209073-Settings_-_Environment_variables_-_Branch_-_create.png", "Settings - Environment variables - Branch - create.png", 1500, 760, "#e9f1f3" ] } ] } [/block] ## Consume the variable in your build Your environment variables will be automatically consumed by tools that are expecting them. [block:callout] { "type": "info", "body": "<a href=\"#section-2a-consume-in-your-custom-build-scripts-\">2a. Consume in your custom build scripts.</a>\n<a href=\"#section-2b-consume-in-android-build-gradle-file-\">2b. Consume in Android build.gradle file.</a>" } [/block] ## 2a. Consume in your custom build scripts. If you would like to access them in your [custom build scripts](doc:custom-prebuild-and-postbuild-steps), use the bash variable expansion syntax. [block:code] { "codes": [ { "code": "./Example.framework/run $Crashlytics_Token", "language": "shell" } ] } [/block] ## 2b. Consume in Android build.gradle file. If you are building an **Android** app with **Gradle** (Android Studio), you can also access them 2 ways inside your **build.gradle** file You can access them via **System.getenv()**, like this: [block:code] { "codes": [ { "code": "buildscript {\n\trepositories {\n\t\tjcenter()\n \tmaven {\n\t\t\tcredentials {\n username System.getenv(\"ARTIFACTORY_USERNAME\")\n password System.getenv(\"ARTIFACTORY_PASSWORD\")\n }\n url System.getenv(\"ARTIFACTORY_URL\")\n\t\t}\n\t}\n\t...\n}", "language": "json" } ] } [/block] We also put these variables inside **gradle.properties** file, so you can access them directly like: [block:code] { "codes": [ { "code": "buildscript {\n\trepositories {\n\t\tjcenter()\n \tmaven {\n\t\t\tcredentials {\n username ARTIFACTORY_USERNAME\n password ARTIFACTORY_PASSWORD\n }\n url ARTIFACTORY_URL\n\t\t}\n\t}\n\t...\n}", "language": "json" } ] } [/block] That's it! If you want to consume your variables from within your app, follow the [Device Variables](/docs/device-variables-1) guide.