Files
oam/knowledge base/azure/devops.md
2023-05-24 19:54:46 +02:00

3.1 KiB

Azure Devops

Table of contents

  1. TL;DR
  2. Pipelines
    1. Predefined variables
    2. Loops
  3. Azure CLI extension
  4. Further readings
  5. Sources

TL;DR

# Login to Azure DevOps with a PAT.
az devops login --organization 'https://dev.azure.com/organization_name'

# List DevOps' Service Endpoints.
az devops service-endpoint list \
  --organization 'https://dev.azure.com/organization_name' --project 'project'
az rest -m 'get' \
  -u 'https://dev.azure.com/organization_name/project_name/_apis/serviceendpoint/endpoints' \
  --url-parameters 'api-version=7.1-preview.4' \
  --headers Authorization='Bearer ey…pw'

# Get the ID of a Service Endpoint from its name.
az devops service-endpoint list -o 'tsv' \
  --organization 'https://dev.azure.com/organization_name' --project 'project' \
  --query "[?name=='service_endpoint_name'].id"

# Get the name of a Service Endpoint from its id.
az devops service-endpoint list -o 'tsv' \
  --organization 'https://dev.azure.com/organization_name' --project 'project' \
  --query "[?id=='service_endpoint_id'].name"

# Filter out users whose Principal Name starts for X and access Y.
az devops user list --org 'https://dev.azure.com/organizationName' \
  --query "
    items[?
      startsWith(user.principalName, 'yourNameHere') &&
      \! contains(accessLevel.licenseDisplayName, 'Test plans')
    ].user.displayName"

# Get Teams' information.
az devops team show \
  --org 'https://dev.azure.com/organizationName' --project 'project' \
  --team 'display_name'

Pipelines

Predefined variables

See Use predefined variables for more information.

Loops

See Expressions for more information.

Use the each keyword to loop through parameters of the object type:

parameters:
  - name: listOfFruits
    type: object
    default:
      - fruitName: 'apple'
        colors: ['red','green']
      - fruitName: 'lemon'
        colors: ['yellow']

steps:
  - ${{ each fruit in parameters.listOfFruits }} :
    - ${{ each fruitColor in fruit.colors}} :
      - script: echo ${{ fruit.fruitName}} ${{ fruitColor }}

Azure CLI extension

Devops offers the az devops extension to the Azure CLI.
The extension will automatically install itself the first time you run an az devops command.

Further readings

Sources

All the references in the further readings section, plus the following: