AutoTester213
AutoTester213

Reputation: 2862

Hidden variable Password parameter - powershell 4.0

I am creating a release definition with a powershell script to replace a file with env variables from the release definition it works but It doesn't seem to catch the password variable which is hidden in the release definition. is there a way to tell powershell to look for hidden variables?

UPDATE: Here is the script it finds all the variables in $paramsFilePath that are not hidden my password in In environmental variables in Release definition is hidden and the script doesn't find it.

param(
    [string]$paramsFilePath,

)

Write-Verbose -Verbose "Entering script Replace-SetParameters.ps1"
Write-Verbose -Verbose ("Path to SetParametersFile: {0}" -f $paramsFilePath)

# get the environment variables
$vars = Get-ChildItem -path env:*

# read in the setParameters file
$contents = Get-Content -Path $paramsFilePath

# perform a regex replacement
$newContents = "";

$contents  | % {
    $line = $_
    if ($_ -match "__(\w+)__") {
        $setting = Get-ChildItem -path env:* | ? { $_.Name -eq $Matches[1] }
        if ($setting) {
            Write-Verbose -Verbose ("Replacing key {0} with value from environment" -f $setting.Name)
            $line = $_ -replace "__(\w+)__", $setting.Value
        }
    }
    $newContents += $line + [Environment]::NewLine
}

Write-Verbose -Verbose "Overwriting SetParameters file with new values"
Set-Content $paramsFilePath -Value $newContents



Write-Verbose -Verbose "Exiting script Replace-SetParameters.ps1"

Upvotes: 1

Views: 1652

Answers (1)

PatrickLu-MSFT
PatrickLu-MSFT

Reputation: 51083

Unlike the normal variable, the password you are trying to get is secret variable.

Secret Variables

We recommend that you make the variable Secret if it contains a password, keys, or some other kind of data that you need to avoid exposing.

The variable replacement we do is on the inputs on the tasks, we don't parse the scripts. To use secret variables you will have to take those as inputs into your script we explicitly do not populate those into the environment. You could take a look at this discuss: Use hidden / secret variables in commands

Upvotes: 1

Related Questions