55 lines
2.0 KiB
PowerShell
55 lines
2.0 KiB
PowerShell
function Set-TeamCityParameter {
|
|
<#
|
|
.SYNOPSIS
|
|
Set a value on the TeamCity parameter for the job.
|
|
|
|
.DESCRIPTION
|
|
The value set here will not be available to other processes until the build-step completes.
|
|
You can use this to set %dep.*.parameter% style parameters on the build server.
|
|
|
|
.PARAMETER Name
|
|
The name of the parameter to set.
|
|
This value can start with env: or system: to affect those specific parameter sets.
|
|
This value will get sanitized.
|
|
This should not affect your end-value, but special characters may need to be validated on first-usage.
|
|
|
|
.PARAMETER Value
|
|
The value to be set.
|
|
This value will get sanitized.
|
|
This should not affect your end-value, but special characters may need to be validated on first-usage.
|
|
|
|
.EXAMPLE
|
|
Set-TeamCityParameter -Name 'rev.dep.*.SomeKey' -Value 'Hi mom!'
|
|
#>
|
|
[CmdletBinding()]
|
|
[OutputType([void])]
|
|
param (
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$Name,
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$Value
|
|
)
|
|
|
|
$logLead = Get-LogLeadName
|
|
|
|
$sanitizedName = ConvertTo-SafeTeamCityMessage -InputText $Name
|
|
$sanitizedValue = ConvertTo-SafeTeamCityMessage -InputText $Value
|
|
|
|
if ($sanitizedName.Substring(0, 6) -eq 'system:') {
|
|
Write-Host "$logLead : Setting a TeamCity parameter on SYSTEM with Name [$($sanitizedName.Substring(7))]"
|
|
}
|
|
|
|
if ($sanitizedName.Substring(0, 6) -eq 'env:') {
|
|
Write-Host "$logLead : Setting a TeamCity parameter on ENVIRONMENT with Name [$($sanitizedName.Substring(4))]"
|
|
}
|
|
|
|
if (Test-IsTeamCityProcess) {
|
|
Write-Host "##teamcity[setParameter name='$sanitizedName' value='$sanitizedValue']"
|
|
} else {
|
|
Write-Host "$logLead : Would set a parameter on the build to Name: [$sanitizedName] Value: [$sanitizedValue]"
|
|
# TODO: Do we want to use this to set local variables?
|
|
# We could have ENV: or SYSTEM: set Env-Vars in Process/Machine, and others Set-Variable -Scope Script/Global
|
|
# Not super-useful, maybe, but could be. Worth a thought.
|
|
}
|
|
}
|