0
0
Azurecloud~5 mins

Azure Pipelines overview - Commands & Configuration

Choose your learning style9 modes available
Introduction
Azure Pipelines helps you automatically build and test your code every time you make a change. It solves the problem of manually checking and deploying code by running these steps for you in the cloud.
When you want to check your code for errors automatically after every change.
When you want to build your app and prepare it for release without doing it by hand.
When you want to run tests on your code to catch problems early.
When you want to deploy your app to a server or cloud automatically after building.
When you want to share your build and test process with your team for consistency.
Config File - azure-pipelines.yml
azure-pipelines.yml
trigger:
  - main

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: UsePythonVersion@0
  inputs:
    versionSpec: '3.x'

- script: |
    python -m pip install --upgrade pip
    pip install -r requirements.txt
  displayName: 'Install dependencies'

- script: |
    python -m unittest discover
  displayName: 'Run tests'

This file tells Azure Pipelines to start a build when code is pushed to the main branch.

It uses a Linux machine with Python installed.

Steps include installing Python dependencies and running tests automatically.

Commands
This command creates a new Azure Pipeline named 'example-pipeline' linked to the specified GitHub repository and branch, using the YAML file for configuration.
Terminal
az pipelines create --name example-pipeline --repository https://github.com/example/repo.git --branch main --yml-path azure-pipelines.yml
Expected OutputExpected
Pipeline 'example-pipeline' created successfully.
--name - Sets the name of the pipeline
--repository - Specifies the Git repository URL
--yml-path - Points to the pipeline YAML configuration file
This command starts a run of the 'example-pipeline' to build and test the code immediately.
Terminal
az pipelines run --name example-pipeline
Expected OutputExpected
Run started for pipeline 'example-pipeline'.
--name - Specifies which pipeline to run
This command lists the most recent run of the 'example-pipeline' so you can check its status and results.
Terminal
az pipelines runs list --pipeline-name example-pipeline --top 1
Expected OutputExpected
[ { "id": 123, "status": "completed", "result": "succeeded", "pipelineName": "example-pipeline" } ]
--pipeline-name - Filters runs by pipeline name
--top - Limits the number of runs shown
Key Concept

If you remember nothing else from this pattern, remember: Azure Pipelines automates building and testing your code every time you change it, so you catch problems early and save time.

Common Mistakes
Not specifying the correct YAML file path when creating the pipeline
The pipeline won't run because it can't find the instructions to build and test your code.
Always use the --yml-path flag with the correct path to your azure-pipelines.yml file.
Triggering the pipeline on the wrong branch
Your pipeline might not run when you expect it to, missing important builds or tests.
Set the trigger branch in the YAML file to the branch you want to monitor, like 'main'.
Summary
Create an Azure Pipeline using a YAML file to define build and test steps.
Run the pipeline manually to check your code immediately.
List pipeline runs to see the status and results of your builds.