question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dollar sign ($) in variable causes variable to not show correctly

See original GitHub issue

Required 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:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
egor-bryzgalovcommented, Feb 24, 2021

@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.

0reactions
lazarillocommented, Feb 23, 2021

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:

    • I call pytest from within the Azure Pipeline Powershell command (specifically AzureCLI@2, scriptType: 'ps').
    • From within pytest, I make a subprocess 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.
    • There is no way to pass the variables from Powershell to Python and to Powershell again, if those variables contain special characters.
    • I have found an ugly solution by generating Powershell PSCredential object, then creating an encrypted password using ConvertFrom-SecureString, then saving that encrypted password to a file, then reading that encrypted password file using Powershell and creating a PSCredential again, then finally calling the Password attribute from the PSCredential 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Secret variables with a dollar sign are not correctly set - GitLab
When a secret variable contains a dollar sign $, the secret variable is not set correctly. It seems the content after the dollar...
Read more >
javascript dollar sign variable not working - Stack Overflow
Try to use $(document).ready function: (function ($) { $(document).ready(function () { $header = $( ...
Read more >
Trying to add dollar sign in front of monetary output results in 2 ...
For some reason, we stopped having trouble when we put the total in a variable and just logged the variable… something like 'var...
Read more >
UsingWW: Getting dollar signs to show in TeX - WeBWorK
The commands are done first so that variables within the commands are not accidentally replaced before they are executed, and variable ...
Read more >
DOLLAR function - Microsoft Support
This is because the DOLLAR function returns the number provided as text. Numbers stored as text are a common cause of spreadsheet errors,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found