DEV Community

Dina Berry
Dina Berry

Posted on • Originally published at dfberry.github.io on

Add Azure Developer CLI deployment ID and UTC timestamp to Bicep files

If you frequently deploy to Azure with Azure Developer CLI, either through your local computer or through an automated pipeline, you need a quick and obvious way to track back from the Azure resource to the pipeline or deployment.

In order to mark the deployment resource itself, use the Azure Developer CLI's deployment().name and the Bicep utcNow() function to mark your deployments. The deployment().name is the name of your environment and a timestamp (expressed as a unix timestamp).

To use these in your bicep file, a sample snippet of code is provided:

param deploymentDateTimeUtc string = utcNow()
param deploymentName string = deployment().name
Enter fullscreen mode Exit fullscreen mode

You can use these variables in your Bicep to add as tags to your resources.

var tags = {
  'azd-env-name': environmentName
  'azd-deployment-id': deploymentName
  'azd-deployment-utc': deploymentDateTimeUtc
}
Enter fullscreen mode Exit fullscreen mode

You can also export the variables as an environment variable to use in post-processing activities.

output DEPLOYMENT_NAME string = deploymentName
output DEPLOYMENT_DATETIME_UTC string = deploymentDateTimeUtc
Enter fullscreen mode Exit fullscreen mode

If you are using Terraform instead of Bicep, with Azure Developer CLI, you still have access to the deployment name but the utcNow() is not available.

Top comments (0)