User scripts
Build Automation supports both pre and post-build custom scripts created by users. You must check these scripts into the source repository, and configure the relative path to the scripts from the root of the repo in the Advanced Settings of a build.
Changing node versions
NVM is installed on the build machines to let you easily switch to a different node version during the build process. The following sample script installs and switches to Node 16.13.0:
#!/usr/bin/env bash
## Source profile
. ~/.profile
## Install NVM modules and set version
nvm install 16.13.0
nvm use 16.13.0
## Output Node version used
node -v
exit 0
Setting environment variables
echo "{environment_variable_name}={value}" >> "$DEVOPS_ENV"
To make an environment variable available to the Unity build and your post-build scripts, define or update the environment variable, and write this value to the DEVOPS_ENV
environment file. The script that creates or updates the environment variable doesn't have access to the new value, but all subsequent processes will have access. The environment variable name is stored as the uppercase version of the name given (testenv
becomes TESTENV
). Only single line environment variables are supported.
Example of writing an environment variable to DEVOPS_ENV
In the pre-build script set the environment variable.
echo "TEST_ENV=Sample environment variable" >> $DEVOPS_ENV
Then in the post-build script echo the environment variable.
echo $TEST_ENV
Access build artifacts in a post-build script
You can access build artifacts for automatic upload to a storefront or to automate some part of the build process using a post-build script. If passing a path using environment variables during a post-build script to a Windows executable, then the cygwin path must be used.
Sample script to get the path to the player
#!/bin/bash
#This is a sample that will simply output the path to the build artifact
echo "START"
PLAYER_PATH=$UNITY_PLAYER_PATH
#If we are using a Windows Builder and using the path to pass it to a native Windows application, we need to properly convert the cygwin player path to windows format
if [[ "$BUILDER_OS" == "WINDOWS" ]]; then
PLAYER_PATH=$(cygpath -wa "$UNITY_PLAYER_PATH")
fi
echo "$PLAYER_PATH"
Mask values in logs
Masking a value prevents a string or variable from being printed in the log. Each masked value is replaced with *****
, regardless of the value contents. You can pass an environment variable or raw value into the mask command.
To mask a string or environment variable, use the ::mask-value::
command.
echo "::mask-value::{value}"
Example: Masking a value
To mask the value "SuperS3cretPassword!"
, set the ::mask-value::
command for the value:
echo "::mask-value::SuperS3cretPassword!"
When this is printed in the log, the output will be displayed as "*****"
.
You must register the value with 'mask-value' before outputting it in the logs.
Example: Masking a variable
To mask the variable DB_PASSWORD
or variable value "SuperS3cretPassword!"
, set the ::mask-value::
command for the variable:
DB_PASSWORD=SuperS3cretPassword!
echo "::mask-value::$DB_PASSWORD"
When either of these are printed to the log, the output will be displayed as "*****"
.
Example: Masking an environment variable
Environment variables set with $DEVOPS_ENV
can be masked. Set the value of the enviornment variable, mask it, and then output the value to the $DEVOPS_ENV
file for use in other scripts.
DB_PASSWORD=SuperS3cretPassword!
echo "::mask-value::$DB_PASSWORD"
echo "DB_PASSWORD=$DB_PASSWORD" >> $DEVOPS_ENV