{"_id":"590a04f6ed80861900cbc782","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"},"user":"55b2d5626862a10d00887af9","parentDoc":null,"project":"55b2d5baa74a380d00e290c4","__v":0,"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"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-10-06T21:43:09.364Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"Buddybuild will automatically analyze your repository and automatically configure itself with the best build settings.  However, if you require custom logic as part of your build, you can specify custom scripts to run at three points during the build.\n\nDuring the build, the VM is yours. This means you can run arbitrary scripts at several points during the build.\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Looking for a detailed walkthrough and common examples?\",\n  \"body\": \"For a detailed walkthrough of how and when teams use custom build steps, and an ever growing list of examples, visit: https://www.buddybuild.com/blog/customizing-the-build-process\"\n}\n[/block]\n\n## Environment Variables\n\n### Common buddybuild Variables\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Variable Name\",\n    \"h-1\": \"Example Value\",\n    \"0-0\": \"`BUDDYBUILD_BUILD_NUMBER`\",\n    \"0-1\": \"`56`\",\n    \"h-2\": \"Note\",\n    \"0-2\": \"\",\n    \"2-0\": \"`BUDDYBUILD_APP_ID`\",\n    \"3-0\": \"`BUDDYBUILD_BRANCH`\",\n    \"2-2\": \"Unique identifier for the app. Useful if you have multiple apps in the same repo.\",\n    \"3-2\": \"Name of the branch currently being built.\",\n    \"3-1\": \"`some-branch`\",\n    \"2-1\": \"`564d3232d83277010014e926`\",\n    \"1-0\": \"`BUDDYBUILD_BUILD_ID`\",\n    \"1-1\": \"`564d3232d83277012014f915`\",\n    \"1-2\": \"Unique identifier for the current build job.\",\n    \"7-0\": \"`BUDDYBUILD_WORKSPACE`\",\n    \"7-1\": \"`/Users/buddybuild/workspace`\",\n    \"7-2\": \"This is the location of the source code on the VM.\\n\\nFor Android, the build output folder is in the exact relative location as your local environment. E.g. if the build output folder is in the app folder locally, it will be at \\\"/Users/buddybuild/workspace/app/build\\\".\",\n    \"8-0\": \"`BUDDYBUILD_SECURE_FILES`\",\n    \"8-1\": \"`/Users/buddybuild/secure_files`\",\n    \"8-2\": \"This is the location of your secure files on the VM.\",\n    \"9-0\": \"`BUDDYBUILD_TRIGGERED_BY`\",\n    \"9-1\": \"`webhook`\",\n    \"9-2\": \"Possible values:\\n  * `webhook`\\n  *   `webhook_pull_request_update`\\n  * `webhook_pull_request_open`\\n  * `ui_triggered`: build is triggered by the \\\"Build Now\\\" button\\n  * `scheduler`: build is triggered by schedule\\n  * `rebuild_of_commit`: build is triggered by the \\\"Rebuild\\\" button\\n  * `api_triggered`: build is triggered by the [buddybuild API](http://docs.buddybuild.com/docs/trigger-a-build)\",\n    \"4-0\": \"`BUDDYBUILD_BASE_BRANCH`\",\n    \"4-1\": \"`master`\",\n    \"4-2\": \"If the current build is a pull request, this is the name of the base branch associated with the PR. Otherwise, this is `\\\"\\\"`.\",\n    \"5-0\": \"`BUDDYBUILD_REPO_SLUG`\",\n    \"6-0\": \"`BUDDYBUILD_PULL_REQUEST`\",\n    \"5-1\": \"`buddybuild/2048-App`\",\n    \"6-1\": \"`526`\",\n    \"6-2\": \"If the current build is a pull request, this is the pull request number.\",\n    \"5-2\": \"The repository slug using the `owner/repo` format.\"\n  },\n  \"cols\": 3,\n  \"rows\": 10\n}\n[/block]\n### iOS-specific variables\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Variable Name\",\n    \"h-1\": \"Example Value\",\n    \"h-2\": \"Note\",\n    \"0-0\": \"`BUDDYBUILD_IPA_PATH`\",\n    \"0-1\": \"`/tmp/build.ipa`\",\n    \"0-2\": \"Only available in post-build. Includes the filename in the path.\",\n    \"1-0\": \"`BUDDYBUILD_APP_STORE_IPA_PATH`\",\n    \"1-1\": \"`/tmp/build-appstore.ipa`\",\n    \"1-2\": \"Only available in post-build. Includes the filename in the path.\",\n    \"2-0\": \"`BUDDYBUILD_SCHEME`\",\n    \"2-1\": \"`2048 - Release`\",\n    \"3-0\": \"`BUDDYBUILD_TEST_DIR`\",\n    \"3-1\": \"`/tmp/sandbox/app/test`\",\n    \"3-2\": \"This is the location of the test product folder.\\n\\nInside you will find multiple files related to tests including `Coverage.profdata`.\"\n  },\n  \"cols\": 3,\n  \"rows\": 4\n}\n[/block]\n### Android-specific variables\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Variable Name\",\n    \"h-1\": \"Example Value\",\n    \"h-2\": \"Note\",\n    \"0-0\": \"`BUDDYBUILD_VARIANTS`\",\n    \"0-1\": \"`release`\",\n    \"0-2\": \"List of the variants being built.\",\n    \"1-0\": \"`ANDROID_HOME`\",\n    \"2-0\": \"`ANDROID_NDK_HOME`\",\n    \"1-1\": \"`/Users/buddybuild/.android-sdk`\",\n    \"2-1\": \"`/Users/buddybuild/android-ndk-r10e`\"\n  },\n  \"cols\": 3,\n  \"rows\": 3\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Don't see a the information you need?\",\n  \"body\": \"No problem! Remember, the **VM is yours** at build step. For instance, you could expose `git` information for the build in the [postclone step](doc:custom-prebuild-and-postbuild-steps#section-post-clone).\"\n}\n[/block]\n###User-defined variables\n\nYou can also define [environment variables](http://docs.buddybuild.com/docs/environment-variables) through buddybuild's dashboard that will be securely stored and made available during the build.\n\n##Post-clone\n\nThe post-clone script will run immediately after git clone, and before we do any analysis of what is in the repo.  \n\nThe **buddybuild_postclone.sh** script should be in the **root** of your repo.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"#!/usr/bin/env bash\\n\\n# Example: Clone Parse example project\\ngit clone https://github.com/example/ParseCloudCode\\n\\n# Example: Expose the commit SHA accessible through $GIT_REVISION_SHA Environment Variable\\nexport GIT_REVISION_SHA=$(git rev-parse HEAD)\\n\\n# Example: Expose the commit author & email through the $GIT_REVISION_AUTHOR in the following format: Author Name <author:::at:::example.com>\\nexport GIT_REVISION_AUTHOR=$(git log -1 --pretty=format:\\\"%an <%ae>\\\")\\n\",\n      \"language\": \"shell\",\n      \"name\": \"buddybuild_postclone.sh\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"buddybuild_postclone.sh Examples\",\n  \"body\": \"Somethings you might want to do in a postclone step\\n- Clone other git repos (e.g., another repository contains your Parse cloud code)\\n- Generate or modify your xcodeproject (e.g., some React Native and Cordova projects require this).\\n- Expose git information (e.g., the author or the commit SHA for the build)\"\n}\n[/block]\n## Pre-build\n\nThis prebuild script will run before the build, but after we have automatically installed dependencies (eg. Cocoapods, Carthage).  \n\nAdd the following file to your repository, **next to your .xcodeproj or build.gradle files**, and we'll pick it up!\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"#!/usr/bin/env bash\\n\\n# Example for adding a key to the Plist\\n/usr/libexec/PlistBuddy -c \\\"Add APP_BRANCH String $BUDDYBUILD_BRANCH\\\"\",\n      \"language\": \"shell\",\n      \"name\": \"buddybuild_prebuild.sh\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"You might want to use a custom prebuild step, if you need to do some extra dependency compilation, add something custom to your plist.\\n\\nWhile you can use this to populate API keys or credentials, you can also access device keys that you've added on the dashboard through the BuddyBuildSDK without doing any custom build steps.\",\n  \"title\": \"buddybuild_prebuild.sh\"\n}\n[/block]\n## Post-build\n\nThis postbuild script will run after the build.  \n\nAdd the following file to your repository, **next to your .xcodeproj or build.gradle files**, and we'll pick it up!\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"#!/usr/bin/env bash\\n\\n# Example of uploading a file to your archive service\\ncurl \\\\\\n -F \\\"file=@$BUDDYBUILD_IPA_PATH\\\" \\\\\\n -F \\\"build_number=$BUDDYBUILD_BUILD_NUMBER\\\" \\\\\\n -F \\\"https://archiveservice.example.com\\n\",\n      \"language\": \"shell\",\n      \"name\": \"buddybuild_postbuild.sh\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"Typically, you'll use this to upload specific artifacts to various service integrations you might have.\\n\\n- If you want to archive the .ipa / .dSYM files for yourself\\n- Sending build artifacts to another service\",\n  \"title\": \"buddybuild_postbuild.sh Examples\"\n}\n[/block]\nIf the postbuild step is not running for you, please check you have code signing set up.\n\nAs with everything, if you need help with anything, please get in touch via Intercom and we will find the best way to solve your problem.\n[block:api-header]\n{\n  \"title\": \"Manually failing the build from a custom build step\"\n}\n[/block]\nWhen some conditions required for your build to be successful are not met, you may want to manually fail the build. To do that, exit from your script with a non-zero status code. That is how we'll know the build must fail.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"#!/usr/bin/env bash\\n\\nif [[ \\\"$BUDDYBUILD_BRANCH\\\" =~ \\\"release\\\" ]]; then\\n\\techo \\\"This script should only be used on release branch!\\\"\\n  echo \\\"Aborting build\\\"\\n  \\n\\texit 1\\nfi\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"custom-prebuild-and-postbuild-steps","type":"basic","title":"Custom Build Steps"}

Custom Build Steps


Buddybuild will automatically analyze your repository and automatically configure itself with the best build settings. However, if you require custom logic as part of your build, you can specify custom scripts to run at three points during the build. During the build, the VM is yours. This means you can run arbitrary scripts at several points during the build. [block:callout] { "type": "info", "title": "Looking for a detailed walkthrough and common examples?", "body": "For a detailed walkthrough of how and when teams use custom build steps, and an ever growing list of examples, visit: https://www.buddybuild.com/blog/customizing-the-build-process" } [/block] ## Environment Variables ### Common buddybuild Variables [block:parameters] { "data": { "h-0": "Variable Name", "h-1": "Example Value", "0-0": "`BUDDYBUILD_BUILD_NUMBER`", "0-1": "`56`", "h-2": "Note", "0-2": "", "2-0": "`BUDDYBUILD_APP_ID`", "3-0": "`BUDDYBUILD_BRANCH`", "2-2": "Unique identifier for the app. Useful if you have multiple apps in the same repo.", "3-2": "Name of the branch currently being built.", "3-1": "`some-branch`", "2-1": "`564d3232d83277010014e926`", "1-0": "`BUDDYBUILD_BUILD_ID`", "1-1": "`564d3232d83277012014f915`", "1-2": "Unique identifier for the current build job.", "7-0": "`BUDDYBUILD_WORKSPACE`", "7-1": "`/Users/buddybuild/workspace`", "7-2": "This is the location of the source code on the VM.\n\nFor Android, the build output folder is in the exact relative location as your local environment. E.g. if the build output folder is in the app folder locally, it will be at \"/Users/buddybuild/workspace/app/build\".", "8-0": "`BUDDYBUILD_SECURE_FILES`", "8-1": "`/Users/buddybuild/secure_files`", "8-2": "This is the location of your secure files on the VM.", "9-0": "`BUDDYBUILD_TRIGGERED_BY`", "9-1": "`webhook`", "9-2": "Possible values:\n * `webhook`\n * `webhook_pull_request_update`\n * `webhook_pull_request_open`\n * `ui_triggered`: build is triggered by the \"Build Now\" button\n * `scheduler`: build is triggered by schedule\n * `rebuild_of_commit`: build is triggered by the \"Rebuild\" button\n * `api_triggered`: build is triggered by the [buddybuild API](http://docs.buddybuild.com/docs/trigger-a-build)", "4-0": "`BUDDYBUILD_BASE_BRANCH`", "4-1": "`master`", "4-2": "If the current build is a pull request, this is the name of the base branch associated with the PR. Otherwise, this is `\"\"`.", "5-0": "`BUDDYBUILD_REPO_SLUG`", "6-0": "`BUDDYBUILD_PULL_REQUEST`", "5-1": "`buddybuild/2048-App`", "6-1": "`526`", "6-2": "If the current build is a pull request, this is the pull request number.", "5-2": "The repository slug using the `owner/repo` format." }, "cols": 3, "rows": 10 } [/block] ### iOS-specific variables [block:parameters] { "data": { "h-0": "Variable Name", "h-1": "Example Value", "h-2": "Note", "0-0": "`BUDDYBUILD_IPA_PATH`", "0-1": "`/tmp/build.ipa`", "0-2": "Only available in post-build. Includes the filename in the path.", "1-0": "`BUDDYBUILD_APP_STORE_IPA_PATH`", "1-1": "`/tmp/build-appstore.ipa`", "1-2": "Only available in post-build. Includes the filename in the path.", "2-0": "`BUDDYBUILD_SCHEME`", "2-1": "`2048 - Release`", "3-0": "`BUDDYBUILD_TEST_DIR`", "3-1": "`/tmp/sandbox/app/test`", "3-2": "This is the location of the test product folder.\n\nInside you will find multiple files related to tests including `Coverage.profdata`." }, "cols": 3, "rows": 4 } [/block] ### Android-specific variables [block:parameters] { "data": { "h-0": "Variable Name", "h-1": "Example Value", "h-2": "Note", "0-0": "`BUDDYBUILD_VARIANTS`", "0-1": "`release`", "0-2": "List of the variants being built.", "1-0": "`ANDROID_HOME`", "2-0": "`ANDROID_NDK_HOME`", "1-1": "`/Users/buddybuild/.android-sdk`", "2-1": "`/Users/buddybuild/android-ndk-r10e`" }, "cols": 3, "rows": 3 } [/block] [block:callout] { "type": "info", "title": "Don't see a the information you need?", "body": "No problem! Remember, the **VM is yours** at build step. For instance, you could expose `git` information for the build in the [postclone step](doc:custom-prebuild-and-postbuild-steps#section-post-clone)." } [/block] ###User-defined variables You can also define [environment variables](http://docs.buddybuild.com/docs/environment-variables) through buddybuild's dashboard that will be securely stored and made available during the build. ##Post-clone The post-clone script will run immediately after git clone, and before we do any analysis of what is in the repo. The **buddybuild_postclone.sh** script should be in the **root** of your repo. [block:code] { "codes": [ { "code": "#!/usr/bin/env bash\n\n# Example: Clone Parse example project\ngit clone https://github.com/example/ParseCloudCode\n\n# Example: Expose the commit SHA accessible through $GIT_REVISION_SHA Environment Variable\nexport GIT_REVISION_SHA=$(git rev-parse HEAD)\n\n# Example: Expose the commit author & email through the $GIT_REVISION_AUTHOR in the following format: Author Name <author@example.com>\nexport GIT_REVISION_AUTHOR=$(git log -1 --pretty=format:\"%an <%ae>\")\n", "language": "shell", "name": "buddybuild_postclone.sh" } ] } [/block] [block:callout] { "type": "success", "title": "buddybuild_postclone.sh Examples", "body": "Somethings you might want to do in a postclone step\n- Clone other git repos (e.g., another repository contains your Parse cloud code)\n- Generate or modify your xcodeproject (e.g., some React Native and Cordova projects require this).\n- Expose git information (e.g., the author or the commit SHA for the build)" } [/block] ## Pre-build This prebuild script will run before the build, but after we have automatically installed dependencies (eg. Cocoapods, Carthage). Add the following file to your repository, **next to your .xcodeproj or build.gradle files**, and we'll pick it up! [block:code] { "codes": [ { "code": "#!/usr/bin/env bash\n\n# Example for adding a key to the Plist\n/usr/libexec/PlistBuddy -c \"Add APP_BRANCH String $BUDDYBUILD_BRANCH\"", "language": "shell", "name": "buddybuild_prebuild.sh" } ] } [/block] [block:callout] { "type": "info", "body": "You might want to use a custom prebuild step, if you need to do some extra dependency compilation, add something custom to your plist.\n\nWhile you can use this to populate API keys or credentials, you can also access device keys that you've added on the dashboard through the BuddyBuildSDK without doing any custom build steps.", "title": "buddybuild_prebuild.sh" } [/block] ## Post-build This postbuild script will run after the build. Add the following file to your repository, **next to your .xcodeproj or build.gradle files**, and we'll pick it up! [block:code] { "codes": [ { "code": "#!/usr/bin/env bash\n\n# Example of uploading a file to your archive service\ncurl \\\n -F \"file=@$BUDDYBUILD_IPA_PATH\" \\\n -F \"build_number=$BUDDYBUILD_BUILD_NUMBER\" \\\n -F \"https://archiveservice.example.com\n", "language": "shell", "name": "buddybuild_postbuild.sh" } ] } [/block] [block:callout] { "type": "info", "body": "Typically, you'll use this to upload specific artifacts to various service integrations you might have.\n\n- If you want to archive the .ipa / .dSYM files for yourself\n- Sending build artifacts to another service", "title": "buddybuild_postbuild.sh Examples" } [/block] If the postbuild step is not running for you, please check you have code signing set up. As with everything, if you need help with anything, please get in touch via Intercom and we will find the best way to solve your problem. [block:api-header] { "title": "Manually failing the build from a custom build step" } [/block] When some conditions required for your build to be successful are not met, you may want to manually fail the build. To do that, exit from your script with a non-zero status code. That is how we'll know the build must fail. [block:code] { "codes": [ { "code": "#!/usr/bin/env bash\n\nif [[ \"$BUDDYBUILD_BRANCH\" =~ \"release\" ]]; then\n\techo \"This script should only be used on release branch!\"\n echo \"Aborting build\"\n \n\texit 1\nfi", "language": "shell" } ] } [/block]