Azure DevOps Output Variable
Wednesday, December 10, 2025
It is supposed to be a simple task. I need the image uri that was pushed by ECRPushImage task in Azure DevOps on the next task. ECRPushImage task has outputVariable variable, so let say I set that to ImageUri on my azure-pipelines.yml
- task: ECRPushImage@1
inputs:
...
outputVariable: 'ImageUri'
According to this article https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#use-output-variables-from-tasks, I also need to set name on the task:
- task: ECRPushImage@1
name: ECR
inputs:
...
outputVariable: 'ImageUri'
So, I can use the variable like following:
- script: echo $(ECR.ImageUri)
But it doesn't work, the variable was not replaced. I also tried other runtime syntax in https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#understand-variable-syntax.
So, I went to the GitHub https://github.com/aws/aws-toolkit-azure-devops/blob/master/src/tasks/ECRPushImage/TaskOperations.ts#L81 and it does a simple task.setVariable().
According to the setVariable documentation https://learn.microsoft.com/en-us/azure/devops/pipelines/process/set-variables-scripts?view=azure-devops&tabs=bash#about-tasksetvariable, we can access the variable without the name, so it becomes:
- task: ECRPushImage@1
inputs:
...
outputVariable: 'ImageUri'
- script: echo $(ImageUri)
And it works! That's after 10 iterations of trials and errors.