Public/Set-BuildEnvironment.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function Set-BuildEnvironment {
    <#
    .SYNOPSIS
        Normalize build system and project details into environment variables

    .FUNCTIONALITY
        CI/CD

    .DESCRIPTION
        Normalize build system and project details into environment variables

        Creates the following environment variables:
            $ENV:BHProjectPath via Get-BuildVariables
            $ENV:BHBranchName via Get-BuildVariables
            $ENV:BHCommitMessage via Get-BuildVariables
            $ENV:BHProjectName via Get-ProjectName

    .PARAMETER Path
        Path to project root. Defaults to the current working path

    .NOTES
        We assume you are in the project root, for several of the fallback options

    .EXAMPLE
        Set-BuildEnvironment

        Get-Item ENV:BH*
    #>

    [cmdletbinding()]
    param(
        $Path = $PWD.Path
    )

    $BuildVars = Get-BuildVariables
    $ProjectName = Get-ProjectName -Path $Path

    $ENV:BHBuildSystem = $BuildVars.BuildSystem
    $ENV:BHProjectPath = $BuildVars.ProjectPath
    $ENV:BHBranchName = $BuildVars.BranchName
    $ENV:BHCommitMessage = $BuildVars.CommitMessage
    $ENV:BHProjectName = $ProjectName

}