Setting pipeline variable contains extraneous double or single quote

Viewed 2728

I have the following command to set a BASE_URL variable in Azure DevOps yaml:

- script: |
    echo "##vso[task.setvariable variable=BASE_URL;]$(PROD-CONTAINER-URL)"
  condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'master'))

However whenever I echo the variable then it looks like this:

https://google.com"

If I replace it with a single quote or put the $(PROD-CONTAINER-URL) inside or outside the quotes then the problem still persists. How can I get around this and what causes it?

3 Answers

To solve this issue in Bash script, you need to remove double quotes or single quotes.

steps:
- script: |
     echo ##vso[task.setvariable variable=BASE_URL;]$(PROD-CONTAINER-URL)
  displayName: 'Run a one-line script'

- script: |
    echo $(BASE_URL)

Then the BASE_URL variable will not contain the quotes.

enter image description here

Fixed using powershell instead. Must be a bash escape issue I'm not aware of:

- powershell: |
    Write-Host "##vso[task.setvariable variable=BASE_URL;]$(TEST-CONTAINER-URL)"
  condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'develop'))
  displayName: "Initialize test base url variable"

I had a similar problem. The only thins we changed recently was the pool image to ubuntu-latest. After this change the problem came out randomically, but not always.

Discovered that with the managed image ubuntu-18.04 the wrong quote is not there anymore:

  pool: 
  vmImage: ubuntu-18.04

Just discovered that this is always the case. Sometime it fails again, just with a very lower frequency.

Related