RousselTMLEARNING

TP · Azure DevOps: from discovery to expertise

Lab: Self-hosted agent and continuous integration pipeline with correction

The correction is integrated into the TP (See the green boxes)

What you will learn in this TP
  • Install a self-hosted agent
  • Write a YAML test pipeline
  • Publish test results and artifacts
  • Add build validation
Mode :

All steps and instructions are shown. Recommended for this lab: semi-guided

Introduction #

Context. The new organization has no hosted agent time yet. You install your own agent and set up continuous integration.

Prerequisites: a free Azure DevOps organization, the Azure CLI (azure-devops extension), Git and Python 3, the Lab 1 project, Docker  ·  Estimated time: 45 min

An online agent, a pipeline that publishes test results and blocks failing pull requests.

Setup #

Guided steps, with their solution.

  1. 1. Install the agent

    Why? A self-hosted agent is free and available right away.

    Create a PAT limited to Agent Pools (read, manage), then download, configure and start the agent in the Default pool.
    See the correction
    read -rsp 'PAT (Agent Pools: read & manage): ' AZP_TOKEN
    mkdir -p ~/azagent && cd ~/azagent
    curl -sLO https://download.agent.dev.azure.com/agent/5.282.0/vsts-agent-linux-x64-5.282.0.tar.gz
    tar xzf vsts-agent-linux-x64-5.282.0.tar.gz
    ./config.sh --unattended --url https://dev.azure.com/<your-organization> --auth pat --token "$AZP_TOKEN" \
      --pool Default --agent poste-local --acceptTeeEula
    ./run.sh &
  2. 2. Write the pipeline

    Why? Publishing results makes failures readable in the Tests tab, without reading logs.

    Create azure-pipelines.yml (pytest tests, PublishTestResults@2, artifact), push it and create the boutique-ci pipeline.
    See the correction
    cd ~/boutique-az && git switch main && git pull
    cat > azure-pipelines.yml <<'EOF'
    trigger:
      branches:
        include: [main]
    pr:
      branches:
        include: [main]
    
    pool:
      name: Default            # agent auto-hébergé ; ou vmImage: ubuntu-latest
    
    steps:
      - script: |
          python3 -m venv .venv
          .venv/bin/pip install -r requirements-dev.txt
          .venv/bin/pytest --junitxml=$(Build.ArtifactStagingDirectory)/rapport.xml
        displayName: Tests
      - task: PublishTestResults@2
        condition: succeededOrFailed()
        inputs:
          testResultsFiles: $(Build.ArtifactStagingDirectory)/rapport.xml
          testRunTitle: Tests boutique
      - task: PublishPipelineArtifact@1
        inputs:
          targetPath: $(Build.SourcesDirectory)
          artifact: boutique
    EOF
    git add azure-pipelines.yml && git commit -m 'ci: pipeline de tests' && git push
    az pipelines create --name boutique-ci --repository boutique --repository-type tfsgit --branch main --yml-path azure-pipelines.yml
    # Pipeline › exécution › onglet Tests : 3 tests réussis
  3. 3. Block failing pull requests

    Why? Build validation tests the merge result before it reaches main.

    Add a build validation policy on main with boutique-ci, then open a pull request that breaks a test.
    See the correction
    REPO=$(az repos show --repository boutique --query id -o tsv); PIPE=$(az pipelines show --name boutique-ci --query id -o tsv)
    az repos policy build create --repository-id $REPO --branch main --build-definition-id $PIPE --blocking true --enabled true --display-name ci --manual-queue-only false --queue-on-source-update-only true --valid-duration 720
    git switch -c taux && sed -i 's/taux=0.2/taux=0.21/' app.py && git commit -am 'feat: taux' && git push -u origin taux
    az repos pr create --source-branch taux --target-branch main --title 'Taux' --work-items $US
    # La stratégie « ci » échoue : la pull request ne peut pas être terminée

Validate your work

Check that each goal above is reached and that you get the result described in the introduction.

Difficulty level : ●●●○○ (3/5)

My progress

  • ⏱ Estimated time : ≈ 45 min

Sign in to track your progress and take notes. Sign in

⭐ Rate this lesson

5.0 initial rating from the teaching team

Sign in to rate this lesson →

💬 Questions about this lesson

No questions yet: be the first to ask for help or share your configuration.

Ask a question about this lesson →

Recommended Articles

Azure YAML pipelines: stages, tasks, variables and templates

Writing Azure pipelines in YAML: trigger and pr triggers, stages, jobs and steps, versioned tasks...

Azure Pipelines agents: hosted, self-hosted and managed pools

Choosing and running Azure Pipelines agents: Microsoft-hosted agents and images, self-hosted agen...

End-to-end CI/CD (1/5): principles and anatomy of a pipeline

Understand end-to-end CI/CD: continuous integration, continuous delivery and continuous deploymen...

End-to-end CI/CD (2/5): continuous integration, testing and quality

Succeed with continuous integration: the test pyramid, unit, integration, contract and end-to-end...

GitLab CI/CD: concepts and architecture

Discover GitLab CI/CD: the DevSecOps platform, the .gitlab-ci.yml file, pipelines, stages and job...

GitHub Actions: concepts and how it works

Discover GitHub Actions: events, workflows, jobs, steps and actions, the Marketplace, hosted runn...

GitHub Actions runners: hosted, self-hosted and ARC

Choosing where workflows run: hosted runners and images, larger runners, self-hosted runners (ins...

End-to-end CI/CD (5/5): GitHub Actions, GitLab CI, Jenkins and Argo CD in practice

Compare and use CI/CD tools: GitHub Actions, GitLab CI, Jenkins, Argo CD and Flux; a complete pip...

Deploying with Azure Pipelines: environments, approvals and service connections

Delivering with Azure Pipelines: multi-stage pipelines, environments, approvals and checks, deplo...

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!