top of page
Writer's picturemicah jardine

Tokenisation in Azure DevOps


Using Tokenisation In Azure DevOps


Azure DevOps has several extensions that allow for tokenisation in builds and releases. Tokenisation is the process of replace a token in a file with a predefined variable. It is very useful in a number of situations in Azure DevOps.


I use the task written by Guillaume Rouchon (link at bottom of page). One of the many useful things you can do with tokenisation is dynamically update ARM parameter files with values from an Azure DevOps variable, and this works particularly nicely when you have defined a variable library (see here for more info on variable libraries).


A typical paramter file to be dynamically updated looks like this.

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "company": {
            "value": "#{company}#"
        },
        "department": {
            "value": "#{department}#"
        },
        "environment": {
            "value": "#{environment}#"
        },
        "location": {
            "value": "#{location}#"
        },
        "application": {
            "value": "#{application}#"
        },
        "owner": {
            "value": "{owner}"
        },
        "storageAccountShortName": {
            "value": "storageaccount"
        },
        "kind": {
            "value": "StorageV2"
        },
        "accessTier": {
            "value": "hot"
        },
        "containers": {
            "value": []
        },
        "skuName": {
            "value": "Standard_LRS"
        }
    }
}

When the tokenisation task runs, it will replace the value of the tokens, with variables of the same name. If you define variable defined as 'Owner = "Micah Jardine"', the task will replace the token #{owner}# with the value of "Micah Jardine".


You can target a single file, or target multiple files using standard pattern matching. If no match is found you can choose to delete the token, or to leave the token. I almost always choose to leave the token, so if I run the task again at a later point in the pipeline any variables that are dynamically generated as part of the pipeline can be tokenised.


For a complete up to date list of its functionality check out the link below.


Links


Micah Jardine.

177 views0 comments

Recent Posts

See All

Simple RBAC Model for Azure & DevOps

Azure RBAC models in Enterprises do not need not be complex. Microsoft recommends having fewer subscriptions and creating granular permissio

©2020 by Micah Jardine - Azure Cloud Blog. Proudly created with Wix.com

bottom of page