How to Add DisplayName to Your Azure DevOps YAML Pipelines
When deploying Azure DevOps Pipelines using YAML, you might want to customize how your pipelines appear in the Azure DevOps UI. One way to do this is by adding a DisplayName to your pipeline definition. This allows you to give your pipeline a more descriptive and user-friendly name, making it easier to identify and manage.
Let's dive into how to add this feature to your YAML pipelines.
The Problem: Generic Pipeline Names
Imagine you have a pipeline that builds and deploys a web application to a test environment. By default, Azure DevOps will label your pipeline using the YAML file name, which might be something like "azure-pipelines.yml." This generic name doesn't provide much context about the pipeline's purpose or target environment.
The Solution: Adding displayName
to Your YAML Pipeline
Adding a displayName
attribute to your YAML pipeline definition solves this issue. This attribute lets you set a custom name for your pipeline that clearly reflects its function and target environment. Here's a basic example:
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: PowerShell@2
displayName: 'Build and Deploy Web Application'
inputs:
targetType: 'inline'
script: |
# Your build and deploy script here
In this example, the displayName
attribute is set to Build and Deploy Web Application
, providing a more informative name than the default "azure-pipelines.yml."
Additional Tips and Best Practices
- Consistency: Use a consistent naming convention across your pipelines. This could include using a prefix (e.g., "Prod-Deployment", "Dev-Build") or a naming structure that reflects the environment and action (e.g., "Build and Deploy to Staging").
- Clear and Concise: Keep your display names clear and concise. Avoid using overly technical terms or jargon that might not be understandable by all stakeholders.
- Target Environment: Reflect the target environment in the display name. For example, "Deploy to Production" or "Build for Testing."
- Pipeline Stages: If your pipeline includes multiple stages (e.g., build, test, deploy), consider adding a
displayName
attribute to each stage as well.
Beyond DisplayName: Additional Customization Options
While displayName
is useful, you can further customize your pipeline experience with these additional features:
- Pipeline Variables: Define variables within your pipeline definition and reference them in the
displayName
attribute. This allows for dynamic naming based on specific pipeline runs or environments. - Pipeline Templates: Use pipeline templates to create reusable pipeline structures and reduce redundancy. This is especially helpful when you have multiple pipelines with similar configurations.
By using these strategies, you can create a clear and organized pipeline workflow that is easy to understand and manage.