RousselTMLEARNING

TP · Azure DevOps: from discovery to expertise

Lab: Project, Boards and protected Repos with correction

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

What you will learn in this TP
  • Create a project with the az devops CLI
  • Create work items and link them to commits
  • Configure branch policies
  • Open a linked pull request
Mode :

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

Introduction #

Context. The team moves to Azure DevOps. You create the project, track work in Boards and protect the main branch so every change is reviewed and linked to a request.

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

A project with its work items, a repository whose main branch requires review and linking, and a linked pull request.

Setup #

Guided steps, with their solution.

  1. 1. Prepare the code

    Why? The same service is used in every lab.

    Create the boutique service and run the tests locally.
    See the correction
    mkdir -p ~/boutique-az && cd ~/boutique-az && git init -b main
    cat > app.py <<'EOF'
    import json, os
    from http.server import ThreadingHTTPServer, BaseHTTPRequestHandler
    
    
    def prix_ttc(ht, taux=0.2):
        if ht < 0:
            raise ValueError("prix négatif")
        return round(ht * (1 + taux), 2)
    
    
    class Handler(BaseHTTPRequestHandler):
        def do_GET(self):
            if self.path == "/sante":
                body = b'{"statut": "ok"}'
            else:
                body = json.dumps({"service": "boutique", "version": os.environ.get("VERSION", "dev"), "prix_ttc": prix_ttc(10)}).encode()
            self.send_response(200)
            self.send_header("Content-Type", "application/json")
            self.send_header("Content-Length", str(len(body)))
            self.end_headers()
            self.wfile.write(body)
    
    
    if __name__ == "__main__":
        ThreadingHTTPServer(("0.0.0.0", 8000), Handler).serve_forever()
    EOF
    cat > test_app.py <<'EOF'
    from app import prix_ttc
    import pytest
    
    
    def test_tva_par_defaut():
        assert prix_ttc(10) == 12.0
    
    
    def test_taux_reduit():
        assert prix_ttc(10, 0.055) == 10.55
    
    
    def test_prix_negatif():
        with pytest.raises(ValueError):
            prix_ttc(-1)
    EOF
    cat > Dockerfile <<'EOF'
    FROM python:3.12-slim
    WORKDIR /app
    COPY app.py .
    ARG VERSION=dev
    ENV VERSION=$VERSION
    RUN useradd --create-home app
    USER app
    EXPOSE 8000
    HEALTHCHECK CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/sante')"
    CMD ["python", "app.py"]
    EOF
    echo 'pytest==9.2.0' > requirements-dev.txt
    printf '__pycache__/\n.pytest_cache/\n.venv/\n' > .gitignore
    python3 -m venv .venv && .venv/bin/pip install -q -r requirements-dev.txt && .venv/bin/pytest -q
    # 3 passed
  2. 2. Create the project

    Why? The CLI makes creation reproducible and scriptable.

    Install the extension, create the Boutique project (Agile process), set defaults and create the boutique repository.
    See the correction
    az extension add --name azure-devops
    az login
    ORG=https://dev.azure.com/<your-organization>
    az devops project create --name Boutique --process Agile --org $ORG
    az devops configure --defaults organization=$ORG project=Boutique
    az repos create --name boutique --query remoteUrl -o tsv
  3. 3. Track work

    Why? Linking a commit to a User Story gives traceability from request to code.

    Create a User Story and a task, then push the code with AB#<id> in the commit message and check the link in the work item.
    See the correction
    US=$(az boards work-item create --type "User Story" --title "Afficher le prix TTC" --query id -o tsv)
    az boards work-item create --type Task --title "Écrire les tests du calcul de TVA" --query id -o tsv
    cd ~/boutique-az && git remote add origin $(az repos show --repository boutique --query remoteUrl -o tsv)
    git add . && git commit -m "feat: service boutique AB#$US" && git push -u origin main
  4. 4. Protect main

    Why? Policies prevent any direct, unreviewed change to the main branch.

    Require a reviewer and a linked item on main, then open a linked pull request with auto-complete and approve it in the UI.
    See the correction
    REPO=$(az repos show --repository boutique --query id -o tsv)
    az repos policy approver-count create --repository-id $REPO --branch main --blocking true --enabled true \
      --minimum-approver-count 1 --creator-vote-counts true --allow-downvotes false --reset-on-source-push true
    az repos policy work-item-linking create --repository-id $REPO --branch main --blocking true --enabled true
    git switch -c affichage && echo '# Boutique' > README.md && git add README.md && git commit -m 'docs: README' && git push -u origin affichage
    az repos pr create --source-branch affichage --target-branch main --title "README" --work-items $US --auto-complete true

Validate your work

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

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

My progress

  • ⏱ Estimated time : ≈ 40 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 DevOps: services, organization and plans

Discover Azure DevOps: Boards, Repos, Pipelines, Test Plans and Artifacts, organizations and proj...

Azure Boards and Azure Repos: planning and collaborating

Organizing work with Azure Boards (Agile, Scrum, Basic and CMMI processes, work items, backlogs, ...

Azure DevOps security, governance and best practices

Running Azure DevOps securely: permissions and groups, protected resources, pipeline authorizatio...

Git for DevOps: branches, code reviews and versions

Organize work with Git in a DevOps approach: trunk-based development or GitFlow, short-lived bran...

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

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

Reusing and securing GitLab pipelines

Industrializing GitLab CI/CD: extends, anchors and !reference, include, CI/CD components and cata...

Building and delivering with GitLab: registry, environments and deployments

Delivering with GitLab CI/CD: building and publishing images to the project registry, package reg...

Azure YAML pipelines: stages, tasks, variables and templates

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

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!