powershellazure-devopsazure-pipelinesazure-releases

How do you use an environment variable within a task group in Azure DevOps?


I have a task group that contains two tasks: one is a PowerShell script that fetches a value, and the second is an "Azure Functions" task that deploys a function. I would like to use the value from the first task in the second task (as an app setting).

My PowerShell script is of the form:

$result = GetSomeResult();

"##vso[task.setvariable variable=Foo;]$Result";

If this were called directly from a release pipeline, rather than within a task group, this would write the contents of $result into the pipeline variable $Foo. I would then be able to use it in other tasks of the pipeline (in this case, the App settings field of the Azure Functions task) as $(Foo).

Screenshot of Azure Functions task

When it is in a task group, however, it does not appear to set the pipeline variable. Instead, it sets an environment variable. I can access it using another PowerShell script via $env:Foo, but I can't work out how to use it from a normal task.

So my question is how can I use the result of the PowerShell script in the Azure Functions task if they are both in a task group?


Solution

  • how can I use the result of the PowerShell script in the Azure Functions task if they are both in a task group?

    You can try the following settings in Task Group.

    PowerShell task:

    Script:

    $result = GetSomeResult();
    echo "##vso[task.setvariable variable=Foo;isOutput=true]$Result"
    

    enter image description here

    Azure Function Task:

    enter image description here

    Set the Default value to the variable Foo: $(foo)

    enter image description here

    Result:

    enter image description here