Files
oam/knowledge base/cloud computing/azure/devops.md
Michele Cereda 25a6f5041a fix: references
2023-12-23 19:44:48 +01:00

5.2 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'

# Clone a repository using a PAT.
git clone 'https://pat_value@dev.azure.com/organization_name/project_name/_git/repo_name'

# Create new repositories.
az repos create --name 'repo_name' \
  --org 'https://dev.azure.com/organization_name' --project 'project_name'

# Delete repositories.
az repos delete --yes --id 'repo_id' \
  --org 'https://dev.azure.com/organization_name' --project 'project_name'

# Create pipelines from YAML definition files.
az pipelines create --name 'pipeline_name' \
  --org 'https://dev.azure.com/organization_name' --project 'project_name' \
  --repository 'repo_name' --repository-type 'tfsgit' \
  --folder-path '\\path\\to\\folder' --yaml-path '/path/in/repo.yaml' \
  --skip-first-run 'true'

# Get the names of all the Pipelines the current user has access to.
az pipelines list --organization 'organization_id_or_name'
az pipelines list --detect 'true' --query '[].name' -o 'tsv'

# Show a specific Pipeline information.
az pipelines show --id 'pipeline_id'
az pipelines show --name 'pipeline_name'

# Start a Pipeline run.
az pipelines run --name 'pipeline_name' \
  --parameters 'system.debug=True' agent.diagnostic="True"

# Get the status of a Pipeline's build run.
az pipelines build show --id 'pipeline_id'
az pipelines build show --detect 'true' -o 'tsv' \
  --project 'project_name' --id 'pipeline_id' --query 'result'

# Download an artifact uploaded during a Pipeline's run.
az pipelines runs artifact download --path 'local_path' \
  --organization 'organization_id_or_name' --project 'project_name' \
  --artifact-name 'artifact_name' --run-id 'run_id'

# Delete pipelines.
az pipelines delete --yes --id 'pipeline_id'

# 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"

# Get the id of the Service Principals linked to Service Endpoints.
az devops service-endpoint list -o 'tsv' \
  --organization 'https://dev.azure.com/organization_name' --project 'project' \
  --query "[?name=='service_endpoint_name'].authorization.parameters.servicePrincipalId"

# 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

Give the --organization parameter, or use --detect true if running the command from a git repository to have it guessed automatically.

--detect already defaults to true.

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: