There is a line for the Cloud

Alex Alex 26 November 2019
There is a line for the Cloud

The configuration and the processes in Microsoft's cloud service "Azure DevOps", you can also control it via the command line instead of via the click-orgies. This article explains how to do it and what is to be observed.

Azure DevOps is the successor brand of Team Foundation Server (TFS) and Visual Studio Team Services (VSTS) is. Microsoft is differentiated by the accessories "Azure DevOps Server" and "Azure DevOps Services" between the locally installable Version and the cloud version. Current Version of the server 2019.0.1, see Release Notes. The editorial deadline for the current Release of the Cloud Sprint 154 is. Herein can be found in the Release Notes the item "Azure DevOps CLI general availability".

a

Of VSTS CLI to Azure DevOps CLI

The control of Azure DevOps via command line (CLI, Command Line Interface) for recurring tasks, or application integration. So you could, for example, create a monitoring software automatically Bugs in Azure, DevOps, when it comes to errors in the current operation. On the command line many it is currently, but not all of the features of Azure DevOps taxes. You can, for example, create projects, Repositories, Pipelines, Work Items, wiki, Banner as well as Teams, groups, and users, and manage. However, you can administer no Repositories to Team Foundation Version Control (TFVC) in order. Also, Adding users to Teams not yet in the offer.

The Azure DevOps CLI since February 2019 as a Preview, but it is now at 8. July 2019 at the stage of "General Availability" is by no means finished, as the post will show. There was already a the predecessor product, the VSTS CLI, that worked in spite of the Cloud suggestive Name with the local TFS (Version 2017 Update 2).

In the case of GitHub, you can still find a branch of the old Development with the statement "VSTS CLI is a new command line interface for Visual Studio Team Services (VSTS) and Team Foundation Server (TFS) 2017 Update 2 and later". This statement, however, is out of date, on the actual project page of Microsoft then reads clearly: "The Azure CLI with the Azure DevOps Extension has replaced the VSTS CLI. The VSTS CLI has been deprecated and will no longer be receiving new features. We recommend that users of the VSTS CLI switch to the Azure CLI and add the Azure DevOps extension.“

Azure CLI as a basis

While the VSTS CLI is a Python-implemented, a standalone tool (vsts, installed in C:\Program Files (x86) war\Microsoft SDKs\VSTS\CLI), is the Azure DevOps CLI is an extension to the General Azure CLI (az). Also az is written in Python and installed in the Standard C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2. The 2 at the end of this file Path indicates that the Azure CLI represents the second Generation of the command-line tools for Azure. The first Generation had as the command name "azure". The second Version (az) was initially called Azure CLI 2.0. Since June 2018 Microsoft differentiated but now with the Azure CLI and Azure Classic CLI between the two products.

the
the
the
the
BASTA! Spring 2020
the

BASTA! Spring 2020

the
the
the
Dr. Holger Schwichtenberg
the
< / h3>Of .NET Framework to .NET Core to migrate or not to migrate, this is (the only) question!

with Dr. Holger Schwichtenberg (www.IT-Visions.de/5Minds IT-Solutions)

the
the
Rainer Stropek
the
< / h3>C#-8 - and .NET-Core-3-Workshop

with Rainer Stropek (software architects/www.IT-Visions.de)

the
the
Adrienne Tacke
the
< / h3>Azure Automation: The Good Parts

with Adrienne Tacke (Adrienne Tacke)

would like to control For a user, the Azure DevOps via the command line, it means that he must first install on its hard disk the current Azure CLI. The latest Version available on http://docs.microsoft.com. For Windows there is a. MSI Installer. Under macOS Installation via homebrew (brew update & using& brew install azure-cli). For Linux-based operating systems you can use apt, yum, zypper, or a manual Installation.

as of The editorial deadline is the Azure CLI Version 2.0.68 from the 3. July 2019 up to date. To be able to the Azure-DevOps-extension for the Azure CLI, you need at least Version 2.0.49 is required. The user can use the Command-line shell of his choice. Under Windows for example, Windows PowerShell, PowerShell Core, the classic Windows Shell (cmd), Windows Terminal or the bash Shell in the Windows Subsystem for Linux (WSL). Here PowerShell 7.0 Preview 1 is to be used, the use of object-oriented Pipeline, and the results of the Azure CLI process. Older versions of PowerShell, but it will function equally. Most of the commands work, of course, also without PowerShell Pipelines in the cmd or bash.

the current Version of the Azure CLI to query, enter az –version, and then get a long table with all the Azure CLI installed command modules and extensions. If you still use an older Version of the CLI, i.e. a newer is present, will be informed at the end of this list of practical way.

Usually these version of the output shows no extensions. An extension you have to install explicitly. You don't need a MSI-package, because the Azure CLI has command az extension add. The Azure-DevOps-CLI-extension to install the Azure CLI using:

a
az extension add --name azure-devops
to see

- only the list of installed extensions, enter:

a
az extension list --output table

To update the Azure CLI to use the current MSI package from. As a result, but will not be updated, the installed extensions, you have to update with az extension update separately, e.g. as follows:

a
az extension update --name azure-devops

the current Version of The Azure-DevOps-CLI-extension, which is at the time of writing, available, version 0.11.0. The modern, agile Microsoft Azure DevOps CLI general availability means not that a product has reached version number 1.0.

Extensive help

help on the available commands, you get: az -h. To note is that you can only command groups (for example, ad, artifacts, boards, devops, iot, pipelines, repos, sql, storage, network, vm, the webapp) gets to see because of the variety of commands in this help output. In a certain command group, you get in, by specifying the name of the command group: az pipelines -h.

Now you get a shorter list with the commands in this command list, where again a distinction is made between direct commands and sub-groups (Fig. 1). And here, too, General Availability does not mean that a product is ready as a whole. Most of the command groups in the Azure DevOps CLI is also available in the Preview, as you can see in figure 1.

the
Fig. 1: help on the command area of Pipeline management,

Fig. 1: help on the command area of Pipeline management, "az pipelines -h": Many of the commands are still in the Preview

the help output in figure 1 that you can enter to list all defined Pipelines: az pipelines list says. You can also request more help for the sub-group of agents with az pipelines-agent -h. There, you will see that there are also on this level is a command list to the list of available Pipeline-receive agent az pipelines agent list. The level of Command and brings subtle differences to days:

the
    the
  • With az pipelines list, it lists the definitions of all the JSON-based Build Pipelines, and the newer YAML Pipelines.
  • the
  • With az pipelines build definition list, you will only receive the JSON-based Build Pipelines.
  • the
  • With az pipelines Release definition list will be delivered the classic Release-Pipelines.

't forget to Register

With the exception of the help commands you can only execute a specific command (Fig. 2), as long as you are not logged in to the Azure DevOps. Microsoft offers three authentication methods:

the
    the
  • By entering az login is the default web browser will open on the Computer and provides an interactive login.
  • the
  • By entering az devops login –organization https://dev.azure.com/OrganisationsName you will be prompted at the command line, a Personal Access Token (PAT) to enter. This can be in the Azure DevOps web portal create. The PAT can be in terms of the rights is limited.
  • the
  • Alternatively, you can put the PAT in an environment variable; this prevents any further logon process: $env:AZURE_DEVOPS_EXT_PAT = bjlhfo7evyvre5rsxhyhxy6.....tv6hklzrrl3ydwfan2k7d5awq"
the
Fig. 2: Start the interactive application via Browser

Fig. 2: Start the interactive application via Browser

preferences

Who works with several organizations and projects, you will need to set the Azure DevOps CLI again and again at the individual commands, the organization and the project name:

a
az pipelines list --organization https://dev.azure.com/ITVDemo --project "miracle list"

it is forced with –organization, the entire URL. An abbreviation of the parameter name is possible if clear:

a
az pipelines list --org https://dev.azure.com/ITVDemo --p "miracle list"

You can abbreviate the organization with –o, there is also the Parameter –output. The constant repetition of these General parameters can be avoided by a Central default:

a
az devops configure --organization https://dev.azure.com/ITVDemo --project "miracle list"

This way you can write in the Following words: az pipelines list

output formats for choice

Azure DevOps CLI Standard all expenses in JSON Format. This is to process for machines is easy to, however, for people not well-readable. A total of

are available: the
    the
  • json (monochrome JSON output)
  • the
  • jsonc (multi-colored JSON output)
  • the
  • none (no output)
  • the
  • table (ASCII table)
  • the
  • tsv (tab-separated)
  • the
  • yaml (YAML)

The output format can be set to each individual in the Azure-CLI command with the Parameter –output, abbreviated -o. How figure 3 shows the table output on the key columns.

the
Fig. 3: output format

Fig. 3: output format "JSONC" versus "Table"

The default output format can be changed by the user persistent in the file c:\users\benutzername\.azure\config (Listing 1). This file he can edit interactively with the command az configure.

[cloud]
name = azure-cloud
[core]
first_run = yes
output = table
collect_telemetry = no
cache_ttl = 10
[logging]
enable_log_file = no

further processing of the results

As a die-hard lover of object-oriented programming and the object-oriented Pipelining with objects in PowerShell is missing the author of this post in the list of output formats, of course, object. One must ask the question, why is Microsoft implementation of Python has used. C# or Visual Basic .NET there are Yes for some time now also platform-neutral, and these languages would have had the advantage of also directly .NET could produce objects for PowerShell. As so often, we also experience here, is that Microsoft, unfortunately, many of the technical decisions are more likely to be taken arbitrarily in individual departments instead of centrally and strategically.

to run The Azure DevOps CLI commands in PowerShell, is still worth, because PowerShell can easily JSON .NET objects to turn; it has been around since Windows PowerShell 3.0, the built-in Commandlet ConvertFrom-Json. This Commandlet converts a string in JSON Format .NET objects to. Intuitively, we would write it as a PowerShell user, then:

a
az pipelines list-o JSON | convertfrom-JSON | where-object { $_.name -notlike "*Backend*" } | sort-object name | format-table name, url

However, it is surprising that, although the table output the two desired columns, but neither of the Filter with the Commandlet where-object is in effect, the sort sort-object. The Commandlet ConvertFrom-Json, the PowerShell development team in the implementation of something has screwed up. If at the root of the JSON file an Array, the Commandlet, the Array in the Pipeline. Usually Commandlets to unpack but an Array into individual objects. Microsoft has not fixed the Problem, unfortunately, today. The workaround for this problem is to either set the Foreach-Object explicitly in the Pipeline:

a
az pipelines list-o JSON | convertfrom-JSON | foreach-object { $_} | where-object { $_.name -notlike "*Backend*" } | sort-object name | format-table name, url
to cling to

or the front part:

a
(az pipelines list-o JSON | convertfrom-JSON) | where-object { $_.name -notlike "*Backend*" } | sort-object name| format-table name, url

Work Items treat

Some of the Azure-DevOps-CLI commands have built-in Filter so you can sort out, for example, Work Items with the SQL-like Work Item Query Language (WIQL):

a
az Board query --wiql "SELECT System.ID, System.Title, System.Work Item Type, The System.AreaPath, System.AssignedTo, System.State from work items in order by the System.ID asc"

With PowerShell variables you can split this command, of course also in several rows:

:
$wiql = "SELECT System.ID, System.Title, System.Work Item Type, The System.AreaPath, System.AssignedTo, System.State from work items in order by the System.ID asc"
az Board query --wiql $wiql

it is Also possible to combine WIQL-Filter and the Filter with Where-Object in PowerShell. The following command filters all of a user's assigned Work Items, which are not done. Then another Filter in the PowerShell Pipeline to the word "Angular" in the title:

:
$wiql = "SELECT System.ID, System.Title, System.AssignedTo, System.State from workitems WHERE [System.AssignedTo] = '[email protected]' and state <> 'Done' order by System.ID asc"
(az Board query --wiql $wiql -o json | convertfrom-JSON).fields | where-object { $_."System.Title" -like "*Angular*" } | format-table "System.ID", "System.Title"

The explicit access .fields is necessary here, because the JSON structure, which provides the Azure CLI is a bit more complex. At the root of an Array of objects. The objects contain the properties of the Work Item, but not directly, but a sub-object „fields“ (Listing 2).

[
{
"fields": {
"System.AssignedTo": {
"_links": {
"avatar": {
"href": "https://nlhsdemo.visualstudio.com/_apis/GraphProfile/MemberAvatars/msa.N2NlNTFmMWYtODBhYy03MzVlLThmOWEtY2FhNzgyNjAzNGQz"
}
},
"descriptor": "msa.N2NlNTFmMWYtODBhYy03MzVlLThmOWEty2fhnzgynjazngqz",
"displayName": "Dr. Holger Schwichtenberg",
"id": "0a31ed99-da1e-4412-913b-5da20050c88f",
"imageUrl": "https://nlhsdemo.visualstudio.com/_apis/GraphProfile/MemberAvatars/msa.N2NlNTFmMWYtODBhYy03MzVlLThmOWEtY2FhNzgyNjAzNGQz",
"uniqueName": "[email protected]",
"url": "https://spsprodcus1.vssps.visualstudio.com/A7fbad96a-dc90-4656-af24-f37c38c5694b/_apis/Identities/0a31ed99-da1e-4412-913b-5da20050c88f"
},
"System.Id": 18,
"System.State": "New",
"System.Title": "security: Secrets, for example, in the connect string, must be stored encrypted"
},
"id": 18,
"relations": null,
"rev": 5,
"url": "https://itvdemo.visualstudio.com/_apis/wit/workItems/18"
},
...
]

Also note the PowerShell-command to work item-the property name in quotation marks if you include points (e.g. System.State and Microsoft.VSTS.Common.Severity). The point of the PowerShell interpreted the same way as other object-oriented languages as a separator between the object and the property. To use dots in the name, was not very wise of Microsoft.

The name of the Work Item characteristics for the processes of Scrum and Agile can be found on the Azure-DevOps cheat sheet attached to this issue. In many cases you can still find VSTS in the name; here are Microsoft will not get rid of the old name, unless you are Breaking Changes risked or implemented aliases.

practical examples

finally, some nice practical examples of how to use the Azure DevOps CLI. The first example shows the Creation of a Work Item with multiple properties (Listing 3). Of az Board work item create, a JSON is requested, the output is evaluated with the help of the PowerShell. Here is a clip of ConvertFrom-Json is not necessary, because the Azure-DevOps-CLI command provides only a single object, not a lot of. In the command to see that you can set a few properties directly on the parameters of the CLI command; most of the properties can be set only via the generic Parameter –fields. To –fields is a list of by an equal sign to separate Name-value pairs:

:
$wi = (az boards work item create --type Bug --title "crash when entering 0 in the price field" --description ", The price column does not allow the number of 0!" --discussion "That I had found in the last Version already!" --field "Microsoft.VSTS.TCM.Repro steps=<div><ol><li>mask, 'invoice' open<li>new account<li>click in item of the invoice, column price<li>0</ol></div>", "Microsoft.VSTS.Common.Acceptance criteria=<div> <b>enter 0</b> must lead to an alert to the user</div>", "Microsoft.VSTS.TCM.System info=Windows 10 v1903" --assigned-to "[email protected]" -o json)
$work itemId = ($wi | ConvertFrom-Json).ID

The second example shows the Change of a Work Item:

a
az Board work-item update --id 30 --field "Microsoft.VSTS.TCM.System info=Windows 10 v1903", "Microsoft.VSTS.Common.Priority=1", "Microsoft.VSTS.Common.Severity=2 - High"

The third example shows the mapping between the two Work Items:

a
az Board work-item relation add --id 21 --target id 24 --relation-type "Tests"

A list of all possible Association types in a project with:

a
az Board work-item relation list-type

finally, the Start of a Build Pipeline:

a
az pipelines build queue --definition-name miracle list angular client build

for More meaningful applications to the Azure DevOps CLI, see this issue of the Windows Developer enclosed cheat sheet.

the

Windows Developer

Windows DeveloperThis article appeared in the Windows Developer. Windows Developer provides comprehensive and vendor-neutral about new Trends and possibilities of Software and system development around Microsoft technologies.

of Course, you can use the Windows Developer on the developers.kiosk digital in the Browser or on their Android and iOS Devices read. In our Shop, the Windows Developer is also in the subscription or single issue available.

the
the
the
the
the

Source: entwickler.de

Comments (0)

    No comments yet

You must be logged in to comment.