In this scenario we want to access predefined variable $Build.Reason
from the PowerShell script. $Build.Reason
will have different value based on what triggered the build.
Map $Build.Reason
to env variable for the powershell script.
- powershell: |
.\scripts\git-package.ps1
env:
BUILD_REASON: $(Build.Reason)
displayName: "push updated package.json to remote git"
Access $env:BUILD_REASON
from the script.
# Write package.json back to github only for release builds
if ($env:BUILD_REASON -eq "Schedule" -or $env:BUILD_REASON -eq "Manual") {
# write package.json back to repo
git push
}
else {
# do nothing
write-verbose "[info] this is not a scheduled build. Build reason is $env:BUILD_REASON "
}
Get list of build variables:
Get list of release variables: