2

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?

1 Answers1

1

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

Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28
  • 1
    Wonderful, thank you so much. I tried everything I could think of, and didn't think of that :-) – Paul O'Leary Sep 08 '21 at 07:57
  • 1
    This solution does not work for me. I have a similar setup, I'm setting the variable inside a PowerShell script in the exact same way (including `isOutput=true`), calling `env | sort` in the next step just to verify that it's set (it is), but I can't use `$(MyVariable)` in later steps in the task group. I also can't use `variables['MyVariable']` in a custom condition, as it's always the initial value that was passed into the task group, not the value that I set it to in the PowerShell script. – vaindil Oct 21 '21 at 18:35