Get Azure Pipeline Build Status with the Azure CLI

This post has been republished via RSS; it originally appeared at: ITOps Talk Blog articles.

I spend a majority of my day working in Visual Studio Code editing files, committing these changes to a git repository, and in some cases triggering Azure Pipeline builds .via the commit and continuous integration. I use the Visual Studio Code terminal for most of these actions. Often times, when triggering an Azure Pipeline build I then open a browser and navigate to the pipeline to check build status. With the new Azure DevOps CLI extension, I can now get build status directly from the Visual Studio Code terminal.

 

In this blog, we will take a quick look at the configuration and basic functionality of the CLI extension as related to Azure Pipelines. For more information on the CLI extension, see the az devops command reference.

 

Prerequisites

 

In order to use the Azure DevOps CLI extension, you need the Azure CLI with a version greater than 2.0.49. Use the az --version command to find the version.

 

az --version

azure-cli (2.0.62)

 

Install and configure the Azure DevOps CLI extension

 

Use the az extension add command to add the Azure DevOps CLI extension. When doing so you will receive a note that the extension is in preview.

 

az extension add --name azure-devops

The installed extension 'azure-devops' is in preview.

 

To validate that the extension is installed correctly, and take a first look at the on-board docs, use the az devops --help command.

 

az devops --help

Group
    az devops : Manage Azure DevOps organization level operations.
        Related Groups
        az pipelines: Manage Azure Pipelines
        az boards: Manage Azure Boards
        az repos: Manage Azure Repos
        az artifacts: Manage Azure Artifacts.

Subgroups:
    admin            : Manage administration operations.
    extension        : Manage extensions.
    project          : Manage team projects.
    service-endpoint : Manage service endpoints/service connections.
    team             : Manage teams.
    user             : Manage users.

Commands:
    configure        : Configure the Azure DevOps CLI or view your configuration.
    feedback         : Displays information on how to provide feedback to the Azure DevOps CLI team.
    invoke           : This command will invoke request for any DevOps area and resource. Please use
                       only json output as the response of this command is not fixed. Helpful docs -
                       https://docs.microsoft.com/en-us/rest/api/azure/devops/.
    login            : Set the credential (PAT) to use for a particular organization.
    logout           : Clear the credential for all or a particular organization.

 

Once the extension is installed, you will also need to ensure that the Azure CLI has been authenticated with Azure. To do so, use the az login command.

 

Get basic information about your build pipeline

 

Now we are ready to work with our build pipelines from the command line. First, let's list the jobs from a particular pipeline project. To do so, we will use the az pipeline build list command.

 

az pipelines build list --organization https://dev.azure.com/nepeters-devops --project scratch-pipeline-designer -o table

ID Number Status Result Definition ID Definition Name Source Branch Queued Time Reason ---- -------- --------- --------- --------------- ---------------- ----------------- -------------------------- ----------- 845 845 completed failed 25 scratch-pipeline master 2019-04-17 00:57:05.623656 manual 639 639 completed succeeded 25 scratch-pipeline refs/pull/4/merge 2019-04-03 16:08:58.156121 pullRequest 638 638 completed succeeded 25 scratch-pipeline refs/pull/3/merge 2019-04-03 16:02:42.750027 pullRequest 637 637 completed succeeded 25 scratch-pipeline refs/pull/2/merge 2019-04-03 15:55:09.467035 pullRequest

 

Note here that we had to specify both the Azure DevOps organization and the project. If you set these as default values, they will no longer need to be specified each time you run a pipeline command. To do so, use the az devops configure command.

 

az devops configure --defaults organization=https://dev.azure.com/nepeters-devops project=scratch-pipeline-designer

 

Now I can get the same results with a simplified command.

 

az pipelines build list -o table

ID    Number    Status     Result     Definition ID    Definition Name   Source Branch      Queued Time                 Reason
----  --------  ---------  ---------  ---------------  ---------------   -----------------  --------------------------  -----------
845   845       completed  failed     25               scratch-pipeline  master             2019-04-17 00:57:05.623656  manual
639   639       completed  succeeded  25               scratch-pipeline  refs/pull/4/merge  2019-04-03 16:08:58.156121  pullRequest
638   638       completed  succeeded  25               scratch-pipeline  refs/pull/3/merge  2019-04-03 16:02:42.750027  pullRequest
637   637       completed  succeeded  25               scratch-pipeline  refs/pull/2/merge  2019-04-03 15:55:09.467035  pullRequest

 

End to end usage

 

Ok, now that this is all configured. Let see how I may use this in my day to day work. Let's assume that I am working on a project in Visual Studio Code. I've updated some files and am now committing these changes to my git repository.

 

Neils-MBP:scratch-pipeline neilpeterson$ git commit -m "Updated Code"
[pr 7896934] Updated Code
 1 file changed, 3 insertions(+), 1 deletion(-)
Neils-MBP:scratch-pipeline neilpeterson$ git push
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 330 bytes | 330.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/neilpeterson/scratch-pipeline.git
   a597150..7896934  pr -> pr

 

The branch that I've committed to is sitting on a PR to master. My build pipeline is configured to run for pull request validation, so I am assuming that this action has triggered a build. What's cool is that now, I can do so without leaving my Visual Studio Code terminal.

 

Here we can see that build 864 has been queued but not started.

 

az pipelines build list -o table

ID Number Status Result Definition ID Definition Name Source Branch Queued Time Reason ---- -------- ---------- --------- --------------- --------------- ----------------- -------------------------- ------------ 864 864 notStarted 25 scratch-pipeline pr 2019-04-18 08:44:11.159324 individualCI 845 845 completed failed 25 scratch-pipeline master 2019-04-16 17:57:05.623656 manual 639 639 completed succeeded 25 scratch-pipeline refs/pull/4/merge 2019-04-03 09:08:58.156121 pullRequest 638 638 completed succeeded 25 scratch-pipeline refs/pull/3/merge 2019-04-03 09:02:42.750027 pullRequest 637 637 completed succeeded 25 scratch-pipeline refs/pull/2/merge 2019-04-03 08:55:09.467035 pullRequest

 

After a moment, I've run the command again, and we can see that build number 864 has completed successfully.

 

az pipelines build list -o table
ID Number Status Result Definition ID Definition Name Source Branch Queued Time Reason ---- -------- --------- --------- --------------- ---------------- ----------------- -------------------------- ------------ 864 864 completed succeeded 25 scratch-pipeline pr 2019-04-18 08:44:11.159324 individualCI 845 845 completed failed 25 scratch-pipeline master 2019-04-16 17:57:05.623656 manual 639 639 completed succeeded 25 scratch-pipeline refs/pull/4/merge 2019-04-03 09:08:58.156121 pullRequest 638 638 completed succeeded 25 scratch-pipeline refs/pull/3/merge 2019-04-03 09:02:42.750027 pullRequest 637 637 completed succeeded 25 scratch-pipeline refs/pull/2/merge 2019-04-03 08:55:09.467035 pullRequest

 

In this post, we have seen basic configuration and usage of the Azure DevOps CLI extension as related to Azure Pipelines. This only scratches the capability surface of the CLI extension. Make sure to checkout out the docs for a complete look at capability and the command reference.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.