Skip to content

Return all variables with matching prefix #137

@fourpastmidnight

Description

@fourpastmidnight

So, I was wondering, what if there happened to be an environment variable already named <PREFIX><Buildvar>, e.g., BHBuildSystem? What would happen? would BuildHelpers overwrite it? None of the function documentation mentioned what would happen, and I couldn't overtly see that anything would be overwritten--in fact, it looked like a check was made. But, still, what would happen? So I ran a test:

PS C:\> ${ENV:BUILD_BuildSystem} = 'Local'
PS C:\> Set-BuildEnvironment -VariableNamePrefix 'BUILD_' -BuildOutput ./out -PassThru

Name                          Value
----                          -----
BUILD_ProjectPath             C:\MyProject\src\MyProject
BUILD_BranchName              build-enhancements
BUILD_CommitMessage           build: Update build script
BUILD_CommitHash              123abc...
BUILD_BuildNumber             0
BUILD_ProjectName             MyProject
BUILD_PSModuleManifest        C:\MyProject\src\MyProject.psd1
BUILD_ModulePath              C:\MyProject\src
BUILD_BuildOutput             C:\MyProject\src\MyProject\out

What happened to the BUILD_BuildSystem variable? It wasn't emitted. Why not? It's still there, of course:

PS C:\> Get-Item $ENV:\BUILD_BuildSystem
Local

It would be better if BuildHelpers returned all environment variables that it would set, even if BuildHelpers did not itself actually set the variable, e.g., if a variable that BuildHelpers would normally set already has a value in the environment, simply return that variable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions