tasks/common.tasks.ps1

# Synopsis: Allows build properties to be overriden by environment variables
task ApplyEnvironmentVariableOverrides {

    $buildEnvVars = Get-ChildItem env:BUILDVAR_*
    foreach ($buildEnvVar in $buildEnvVars) {
        # strip the 'BUILDVAR_' prefix to leave the variable name to be overridden
        $varName = $buildEnvVar.Name -replace "^BUILDVAR_",""

        $res = Set-VariableFromEnvVar -VariableName $varName -EnvironmentVariableName $buildEnvVar.Name

        if ($res) {
            Write-Build Yellow "Overriding '$varName' from environment variable [Type=$($varType.Name)]"
        }
    }
}