Azure Boards - Harness

Hey All!

Azure is growing, that is undeniable, and as they grow, their suite of tools will continue to grow. Not too long ago I created a post on Microsoft Teams integration (alternative to Slack) for your Workflow Notifications. Now, with customers adopting Azure more and more, we are beginning to see Azure Boards (alternative to Jira) become more prevalent. So, in the same vein as the Microsoft Teams post, I have built out an integration for Azure Boards and will post that here!

A note before we start, this is integration is on the Harness roadmap to be built out, so this is intended to be a stop-gap in the meantime. Additionally, this is built out to be a somewhat robust integration, but you can get very advanced with what you can do in Azure Boards and with this integration (I will try to point out those areas throughout the post).

Azure Information

There are somethings that will need to be brought in from Azure for you to use this integration:

  • Azure Org (i.e.
  • Azure Personal Access Token
    • You might want to create a Harness Service Account that can be used for this. It will need Full Access
    • To get the Personal Access Token (PAT) from Azure, follow these steps:
  1. Sign-in to Azure DevOps
  2. Click User Icon in top right
    a. 3 dots and User Settings
    b. PAT
  3. Create PAT with Full Access
  4. Save the PAT somewhere for the time being
  • Azure Work Item information:
    • Work Item Type (Epic, Issue, and Task are the default)
    • Work Item Area
    • Work Item Iteration
    • Work Item States (To Do, Doing, and Done are the default)
    • Work Item Assigned To (Designate someone to be the default user to assign the Work Items to)
    • Work Item Projects

Harness: Delegate Profile

The easiest way to bring in this integration is to use the Azure CLI. To do this, you’ll need to add the following script into a Delegate Profile:

echo “ “ && echo "apt-get update" && echo “ “
apt-get update
echo “ “ && echo "install pip" && echo “ “
apt-get -y install python-pip
echo “ “ && echo "check pip version" && echo “ “
pip -v
echo “ “ && echo "install azure cli" && echo “ “
pip install azure-cli
echo “ “ && echo "check azure version" && echo “ “
az version
echo “ “ && echo “adding azure devops” && echo “ “
az extension add --name azure-devops

After that is done, you’ll need to assign the Delegate Profile to a Delegate and give it a Tag as well (i.e. az-cli)

The above steps will give the delegate both the Azure CLI and the Azure CLI DevOps Extension. Additionally, once the CLI is on the Delegate and the Delegate is tagged appropriately, we are ready to move to the actual implementation piece.

Harness: Secret

Before we get to the script, we will want to add the Azure PAT into Harness in a way where we can keep it secure. The best way to do this is by adding it to the Harness Secrets Manager and then referencing it later.

Harness: Template Library

Azure Boards uses the term Work Items to indicate the tickets or issues that you can use. As such, we want to be able to create and/or update those Work Items throughout the Harness Workflows and/or Pipelines. Therefore, we will be creating two Shell Scripts in the Harness Template Library: AZ-Boards - Create Work Item and AZ-Boards - Update Work Item

Harness: Create Work Item

This is the final product that we will be creating for the Create Work Item piece.

The template for this is:

echo ${secrets.getValue("Azure_PAT")} az devops login --organization ${azureOrg}

export AZURE_WI_ID=`az boards work-item create --title "${wiTitle}" --type ${wiType} --area "${wiArea}" --assigned-to ${wiAssignedTo} --description "${wiDescription}" --discussion "${wiDiscuss}" --project ${wiProject} --query id`

The first line of the template enables us to login to the organization using the Azure_PAT secret. Once that is done, the template will then execute the desired Work-Item Create command and output the Work Item ID into the variable AZURE_WI_ID (for later use). You will notice that the final setup has the different variables which tie to Workflow Variables in Harness, so make sure that this is in place. Also, any information that will be hardcoded, such as a default Assigned To user, can be added in the Values section for the appropriate Variable (If this will never change, then you can hardcode it in the template instead of using a variable. Lastly, you’ll want to make sure that the Script Output shows

Once you have this in the Template Library, you can make the Update Work Item template.

This screenshot is the final look for the Update Work Item.

The template for this is:

echo ${secrets.getValue("Azure_PAT")} az devops login --organization ${azureOrg}

az boards work-item update --id ${wiID} --discussion "${wiDiscuss}" --state ${wiState}

The first line will ensure that we have logged into the appropriate organization. The next line allows us to update the Work Item that was created in the Create Work Item template by leveraging the Work Item ID from the output.

After both of these are done in the Template Library, you will want to link them in the desired Harness Workflow.

Harness: Workflow

To start off, we will want to make sure that the Workflow Variables are set correctly.

You’ll notice that there are some variables in the Default Values section, as well as some pre-filled information. This is not a requirement, but it would be good if there were default values to both show what values are allowed and also allow for quick execution of the workflow as needed. Additionally, some of the variables added are things like who triggered it and what is the deployment URL to be added to the Work Item Discussion. Here is a link for some of the other things you can do with a Workflow Variable that might be useful (Like a list of possible options for the end users in the case of the Work Item State).

Now, we will want to add a step in the pre-deployment part of the Workflow and link the Create Work Item template:

A few things of importance here are:

  1. Add the tag you assigned to the delegate in the Tags section
  2. Check the box that says “Publish output in the context”
    a. Publish Variable Name = azure
    b. Scope = Pipeline
  3. If you did not fill in the variable values in the Template Library, make sure to do that now

Then, link the Update Work Item template in a later portion of the Workflow

This script will reuse variables that have already been filled out in the Create Work Item script. You can reuse the Update Work Item template as many times as needed, you will just need the Work Item ID to provide to the template (This also means that you can have Harness update the Work Item that Harness did not create by passing in the Work Item ID to the Workflow).

Once this is finished, if you would like to test it out, add an approval step in-between the two Steps to see the output in Harness and the Azure Board Work Item:

(Note: Not all read in the context is bad, so keep that in mind)

Hopefully this helps!

Don’t forget to Like/Comment/Share!


Solid bud like always!