I have the following function:
function Add-Variable {
Param
(
[Parameter(Mandatory=$true, Position=0)]
[string] $ProjectName,
[Parameter(Mandatory=$true, Position=1)]
[string] $VariableGroupId,
[Parameter(Mandatory=$true, Position=2)]
[string] $VariableName,
[Parameter(Mandatory=$true, Position=3)]
[string] $Value,
[Parameter(Mandatory=$false, Position=4)]
[bool] $IsSecret = $false
)
Write-Host
Write-Host "Adding $($VariableName) variable..."
$DeploymentPath = az pipelines variable-group variable create --project $ProjectName --group-id $VariableGroupId --name $VariableName --value $Value | Null-Check $VariableName
}
I have multiple calls to this function e.g.
Add-Variable $ProjectAlias $GlobalVarGroup.id 'Deployment.Path' 'D:\Websites\$(Hostname)'
Add-Variable $ProjectAlias $GlobalVarGroup.id 'Apppool.Username' $IISUser
however, when i make the following call:
Add-Variable $ProjectAlias $GlobalVarGroup.id 'Log.Path' '\\svr-prdfs\$(ASPNETCORE_ENVIRONMENT)\Logs\$(Hostname)\$(Agent.MachineName)'
I get this error:
az : \Logs\$(Hostname)\$(Agent.MachineName) was unexpected at this time.
At C:\Users\richa\OneDrive\Documents\Azure CLI\helpers.ps1:24 char:23
+ ... ymentPath = az pipelines variable-group variable create --project $Pr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (\Logs\$(Hostnam...d at this time.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
I wonder if this is due to the string being passed containing values such as $(Agent.MachineName)
, however, I am passing these in single quotes so I would expect them to be evaluated as a literal string.
Further to this, the above call works where 'D:\Websites\$(Hostname)'
is passed as a parameter, so this would seem to contradict this theory.
Does anyone know what the issue is here?
Here is an example of what I am trying to achieve - this is what I have entered manually into azure devops and am looking to do this via azure cli.