Search code examples
powershelltfstfsbuild

change build variable with powershell not working


I want to change the tfs variable BUILD_SOURCEBRANCHNAME while building, using this powershell script in my build step:

##vso[build.sourcebranch]master

This doesn't throw errors, but is not working either?

How can I achieve this?


Solution

  • The syntax to change any environment variable in Azure DevOps is:

    Write-Host "##vso[task.setvariable variable=someVar]varValue"
    

    So in your case, if you want to "fake" the source branch:

    $fakeBranch = "shayki"
    Write-Host "##vso[task.setvariable variable=build.sourcebranch]$fakeBranch"
    Write-Host "##vso[task.setvariable variable=build.sourcebranchname]$fakeBranch"
    

    The variables before:

    enter image description here

    The script:

    enter image description here

    The variables after:

    enter image description here