0
0
Azurecloud~5 mins

Build pipeline basics in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
A build pipeline automates the process of turning your code into a working application. It helps catch errors early and makes sure your app is ready to run every time you change the code.
When you want to automatically check your code for mistakes after every change.
When you need to create a ready-to-use app package without doing it manually.
When you want to save time by running tests and builds automatically.
When you want to share your app with others quickly and reliably.
When you want to keep your app updated with the latest code changes.
Config File - azure-pipelines.yml
azure-pipelines.yml
trigger:
  - main

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: UsePythonVersion@0
  inputs:
    versionSpec: '3.x'
  displayName: 'Use Python 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'

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'
  displayName: 'Publish artifacts'

trigger: Runs the pipeline on changes to the main branch.

pool: Uses a Linux machine to run the steps.

steps: Defines the tasks: set Python version, install dependencies, run tests, and publish build results.

Commands
This command creates a new Azure DevOps build pipeline using the YAML file in the repository. It sets up the pipeline to run on the main branch.
Terminal
az pipelines create --name example-build-pipeline --repository https://github.com/example/repo.git --branch main --yml-path azure-pipelines.yml
Expected OutputExpected
Pipeline 'example-build-pipeline' created successfully.
--name - Sets the name of the pipeline
--repository - Specifies the Git repository URL
--branch - Specifies the branch to trigger the pipeline
--yml-path - Points to the pipeline YAML file
This command starts a manual run of the build pipeline to test if it works as expected.
Terminal
az pipelines run --name example-build-pipeline
Expected OutputExpected
Run started for pipeline 'example-build-pipeline'. Run ID: 123
--name - Specifies which pipeline to run
This command shows the latest run of the build pipeline so you can check its status and results.
Terminal
az pipelines runs list --pipeline-name example-build-pipeline --top 1
Expected OutputExpected
[ { "id": 123, "status": "completed", "result": "succeeded", "sourceBranch": "refs/heads/main" } ]
--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: a build pipeline automatically checks and prepares your app every time you change your code.

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 your app.
Always use the --yml-path flag with the exact path to your azure-pipelines.yml file.
Triggering the pipeline on the wrong branch or forgetting to set triggers.
Your pipeline might not run when you expect it to, missing important code changes.
Set the trigger section in the YAML to the branch you want to monitor, like 'main'.
Skipping the test step in the pipeline.
Errors in your code might go unnoticed and cause problems later.
Include a test step to catch issues early before publishing artifacts.
Summary
Create a build pipeline using a YAML file that defines steps to prepare your app.
Run the pipeline manually to check it works and view the results.
Use triggers to automate the pipeline on code changes to keep your app updated.