Dollar sign ($) in variable causes variable to not show correctly
See original GitHub issueRequired Information
Entering this information will route you directly to the right team and expedite traction.
Question, Bug, or Feature?
Type: Bug
Enter Task Name: PowerShell
Environment
- Server - Azure Pipelines
- Agent - Hosted (vs2017-win16)
Issue Description
I’m trying to send an email that contains a URL with a $ in it but nothing I do can get the URL to show correctly in the email. After trying various escape sequences or storing the URL as a cross task variable, I discovered that even putting a $ in a cross task variable causes problems.
This problem can be seen by running these two inline PowerShell tasks:
$urlbase = 'https://foobar.blob.core.windows.net/$' + 'web/software/'
Write-Host "##vso[task.setvariable variable=DownloadURLBase;isOutput=True]$urlbase"
echo $(DownloadURL.DownloadURLBase)
The first script needs the Output Variable reference name set to DownloadURL, otherwise the second script won’t recognize the variable or display it at all, even malformed.
In the second task, I expect the log to say https://foobar.blob.core.windows.net/$web/software
, but instead I see https://foobar.blob.core.windows.net//software
.
I intentionally split the string in half at the dollar sign to try and prevent Azure Pipelines from performing macro processing on the token $web
. But as I said, no combination of escaping, string concatenation, using single / double quotes or anything else I can think of is getting the phrase “$web” to show up in the log (and email body) as expected.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (5 by maintainers)
@lazarillo Thank you for the explanation. I understand your situation. So I’m closing this issue. Please feel free to create a new one if you face any problems.
Hi @egor-bryzgalov,
Sorry it took me a while to respond:
The azure pipeline works fine. So you can close this issue.
But to answer your follow up question: no, my password is not passed correctly, but this is a Powershell problem, not an Azure pipelines problem. I will explain it since you asked:
pytest
from within the Azure Pipeline Powershell command (specificallyAzureCLI@2
,scriptType: 'ps'
).pytest
, I make asubprocess
call to Powershell where I try to log in to a remote machine – the test is to ensure that IaC resources were deployed properly. I make an SSH call into a Windows machine, using Powershell.PSCredential
object, then creating an encrypted password usingConvertFrom-SecureString
, then saving that encrypted password to a file, then reading that encrypted password file using Powershell and creating aPSCredential
again, then finally calling thePassword
attribute from thePSCredential
and deleting the file with the encrypted password.I have not been able to find a better way to deal with passing secret credentials between languages.
I am not complaining, as I said, this is not an Azure pipelines issue. It is a Powershell issue. And I found a solution. It is robust, or seems so. It is just such a hassle to do something that I felt must be fairly common.