Is there a variable available for an Azure devops pipeline task step name, highlighted below?
pipeline image screenshot
I’ve looked through the predefined variables at https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=classic but none of them work/are suitable.
2
Answers
From your description, you want to use Pipeline variable to set the Task Group name.
I am afraid that there is no such pipeline variable can achieve this requirement.
The Pipeline variable will only be expanded when the pipeline is running. Then the pipeline variable will update the task name.
When you set a variable in the task definition, it cannot be expanded directly.
The workaround is that you can hardcode the task name in task definition. In this case, it will show the expected task name.
For more detailed info, you can refer to this doc: Define variables
Since you are using the classic build pipeline, you can call the build definition REST API to get the task steps names and then set the task names as pipeline variables using logging commands – SetVariable. After that you can use the defined variables in the subsequent tasks in pipeline.
To do that by following below steps:
1.Enable the option "
Allow scripts to access OAuth token
" in Agent job. (Reference the following screenshot for the task steps involved in this sample)2.Add a PowerShell task to set task step variables by running the
following script: (In this sample we defined the variable
taskcount
andTaskStep$i
)3.Add another PowerShell task and run below command to check the
defined
TaskStep
variables:4.Use the variables in the subsequent tasks in pipeline. Print variable value for example using PowerShell task: