Issue With Yaml Variable Assignment With Bash

Solution for Issue With Yaml Variable Assignment With Bash
is Given Below:

I am having issues when trying to assign variables with the following syntax in a yaml file. The follow code is taken from the Microsoft Doc on Define variables under the section Understand variable syntax:

variables:
- name: one
  value: initialValue 

steps:
  - script: |
      echo ${{ variables.one }} # outputs initialValue
      echo $(one)
    displayName: First variable pass
  - bash: echo '##vso[task.setvariable variable=one]secondValue'
    displayName: Set new variable value
  - script: |
      echo ${{ variables.one }} # outputs initialValue
      echo $(one) # outputs secondValue
    displayName: Second variable pass

Specifically I found the issue being in the area with the syntax '##vso[task.setvariable variable=one]secondValue'
Note: That I am not using a string written straight into the line above I am using a bash variable with the syntax $variableName in place of secondValue

The issue is:

variables:
- name: one
  value: "initialValue" 

steps:
- task: Bash@3
    inputs:
        targetType: 'inline'
        script: |
            valueTwo="New Value"
            echo '##vso[task.setvariable variable=one]$valueTwo'
    displayName: "Change Variable"

- task: Bash@3
    inputs:
        targetType: 'inline'
        script: |
            echo $(one)
    displayName: "Check Variable Has Changed"

Expected Output: New Value
Real Output: $valueTwo

The parameter expansion called for here is not executed within single quotes, so use double quotes:

            echo "##vso[task.setvariable variable=one]$valueTwo"