英文:
Azure DevOps Release pipeline - How to ensure full name of output variable stays consistent
问题
I am working on a Release pipeline in Azure DevOps, and trying to pass an output variable between different tasks in the same job.
The pipeline looks roughly like this:
Stage
|- Job A
|- Task group 1
|- Task 1.1
|- Task 1.2 - Set output variable 'foo=bar' in PowerShell task
|- Task group 2
|- Task group 3 - Accept variable 'foo' as parameter with value 'bar'
|- Job B
|- Task group 1
|- Task 1.1
|- Task 1.2
|- Task 1.3 - Set output variable 'foo=abc' in PowerShell task
|- Task group 2
|- Task group 3 - Accept variable 'foo' as parameter with value 'abc'
I am able to set the output variable 'foo' to the expected value. However, when trying to list all variables (via Bash task 'env | sort'), in environment variables I can see its name is prefixed with task name like "PowerShell4".
As a result, for task parameter I have to use $(POWERSHELL4.FOO)
instead of $(FOO)
. This is not a reliable name (imagine if a new PowerShell task gets added to the pipeline before my custom task).
Microsoft documentation on this suggests giving a reference name to the task:
> In the Output variables section, give the producing task a reference name. Then, in a downstream step, you can use the form $(<ReferenceName>.<VariableName>)
to refer to output variables.
However, I am not able to set reference name ('refName') for the PowerShell task which sets the output variable, because there is no such option in the UI.
This is easy to do using YAML pipeline instead of Classic pipeline, however in this case it is not an option.
Question: Is there a way I can use to reliably get the value of output variable using a fixed name (such as $(MYCUSTOMNAME.FOO)
), and pass it as a parameter to any other tasks/task groups in the same job in Classic pipeline?
英文:
I am working on a Release pipeline in Azure DevOps, and trying to pass an output variable between different tasks in the same job.
The pipeline looks roughly like this:
Stage
|- Job A
|- Task group 1
|- Task 1.1
|- Task 1.2 - Set output variable 'foo=bar' in PowerShell task
|- Task group 2
|- Task group 3 - Accept variable 'foo' as parameter with value 'bar'
|- Job B
|- Task group 1
|- Task 1.1
|- Task 1.2
|- Task 1.3 - Set output variable 'foo=abc' in PowerShell task
|- Task group 2
|- Task group 3 - Accept variable 'foo' as parameter with value 'abc'
I am able to set the output variable 'foo' to the expected value. However, when trying to list all variables (via Bash task env | sort
), in environment variables I can see its name is prefixed with task name like "PowerShell4".
As a result, for task parameter I have to use $(POWERSHELL4.FOO)
instead of $(FOO)
. This is not a reliable name (imagine if a new PowerShell task gets added to the pipeline before my custom task).
Microsoft documentation on this suggests giving a reference name to the task:
> In the Output variables section, give the producing task a reference name. Then, in a downstream step, you can use the form $(<ReferenceName>.<VariableName>)
to refer to output variables.
However, I am not able to set reference name (refName
) for the PowerShell task which sets the output variable, because there is no such option in the UI.
This is easy to do using YAML pipeline instead of Classic pipeline, however in this case it is not an option.
Question: Is there a way I can use to reliably get the value of output variable using a fixed name (such as $(MYCUSTOMNAME.FOO)
), and pass it as a parameter to any other tasks/task groups in the same job in Classic pipeline?
答案1
得分: 0
I implemented a workaround for this issue by removing the task parameter from Classic pipeline task group and picking up the value 'bar'/'abc' directly from environment variables in the target script, like so:
$variable = Get-ChildItem env: |
Where-Object "Name" -like "*_foo" |
Where-Object "Value" -ne $null |
Select-Object -First 1
$foo = $variable.Value
英文:
In the end I implemented a workaround for this issue by removing the task parameter from Classic pipeline task group and picking up the value 'bar'/'abc' directly from environment variables in the target script, like so:
$variable = Get-ChildItem env: `
| Where-Object "Name" -like "*_foo" `
| Where-Object "Value" -ne $null `
| Select-Object -First 1
$foo = $variable.Value
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论