skip to Main Content

On a MS-hosted Azure pipeline running on ubuntu, within a bash script task, I am setting some pipeline variables that need to be available to another task. These variables are oftentimes maps, in the following format:

{ "1.0.0" = "my-function-app-url.com" }

This will fail the below command, because those maps (stored in the $VALUE variable, have double quotes, which will be interpreted at the end of the bash script.

echo "##vso[task.setvariable variable=$KEY;isOutput=true;issecret=true]$VALUE"

I have tried to use single quotes to enclose the string being echoed, but the behaviour is the same. I have also tried to escape the double quotes within the variables, but again, the behaviour is the same! I have even tried to remove the quotes, but then the hashtag symbol is interpreted as a bash comment…

Is there a way to achieve what I want here?

2

Answers


  1. You need to add in the definition of your variables. Refer to the following yaml:

    pool:
      vmImage: ubuntu-latest
    
    variables:
    - name: VALUE
      value: ""1.0.0" = "my-function-app-url.com"" 
    
    steps:
    - task: Bash@3
      name: setOutput
      inputs:
        targetType: 'inline'
        script: 'echo "##vso[task.setvariable variable=ValueWithQuotes;isOutput=true]$VALUE"'
    
    - task: Bash@3
      inputs:
        targetType: 'inline'
        script: |
          echo '$(setOutput.ValueWithQuotes)'
    

    In the log of the first bash task, you can see ##[debug]Processed: ##vso[task.setvariable variable=ValueWithQuotes;isOutput=true]"1.0.0" = "my-function-app-url.com" .

    The result of the second bash task:

    enter image description here

    Login or Signup to reply.
  2. I have code two samples for setVariable with quotes based on above yml. just have a try and hope this can help.

    pool:
      vmImage: ubuntu-latest
    
    variables:
    - name: VALUE
      value: '{ "1.0.0" = "my-function-app-url.com" }'
    
    steps:
    - task: Bash@3
      name: setOutput
      inputs:
        targetType: 'inline'
        script: echo "##vso[task.setvariable variable=ValueWithQuotes;isOutput=true]$VALUE"
    
    - task: Bash@3
      name: setOutput1
      inputs:
        targetType: 'inline'
        script: echo "##vso[task.setvariable variable=ValueWithQuotes1;isOutput=true]'$VALUE'"
    
    - task: Bash@3
      inputs:
        targetType: 'inline'
        script: |
          echo '$(setOutput.ValueWithQuotes)'
    
    - task: Bash@3
      inputs:
        targetType: 'inline'
        script: |
          echo '$(setOutput1.ValueWithQuotes1)'
    

    below is my two results:

    enter image description here

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search