Search code examples
azure-devopsyamlazure-pipelinesazure-pipelines-yaml

DevOps environments show dynamically set build name


I have a YAML pipeline that deploys to environments specified in Azure DevOps. We want to use the environments so that we can easily see what version is currently deployed in each environment. By default the environments only shows the ID of the build which isn't helpful for identifying what was deployed. enter image description here

If I set a custom name in the YAML then that value is used and displayed as expected.

name: "Example of a name"

enter image description here

However, I need to set the build name dynamically. I do that using the YAML below which is getting the name from the resource (pipeline) that contains the build being deployed.

BuildName=$(resources.pipeline.BuildResource.runName)
echo "##vso[build.updatebuildnumber]$BuildName"

This updates the name on the build, but doesn't flow through to the Environments page where it is back to showing the standard number. enter image description here But it does show correctly on the build. enter image description here

How do I get the environments page to show the dynamic build name/id? Without this the Environments page is practically useless as you can't see at a glance what is deployed in each environment. Or, are there any alternative approaches.


Solution

  • It's a limit that changing build name by logging command dynamically works in the pipeline but not in the Environment. There is already a suggestion ticket Build Number Not Updated In Environments View If Changed In Pipeline. You can submit a vote if you want such a feature.

    To check which build is deploying in the current environment, it's suggested that you custom the build name using property name based on the current build.

    For example,

    name: $(TeamProject)_$(Build.DefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:r)
    

    Then you can see the Environment is like this: enter image description here

    See the detailed info from Configure run or build numbers.