Microsoft Azure · Delivery

CI/CD Pipelines

Continuous delivery turns every merged change into a tested, deployable release. GitHub Actions can deploy to Azure without storing any passwords.

Advanced 5 min Lesson 23 of 28
0/28 in Microsoft Azure
On this page · 5 min · Advanced

Learning objectives#

  • Authenticate to Azure from GitHub with OIDC
  • Build, test and deploy in one workflow
  • Use environments and approvals
  • Deploy safely with slots

Explanation#

OpenID Connect (OIDC) federation lets a workflow exchange a short-lived GitHub token for an Azure token. You configure a federated credential on an app registration or user-assigned managed identity — no client secret is stored.

The azure/login action signs in; azure/webapps-deploy deploys the build output.

GitHub environments add protection rules such as required reviewers before production.

Deploying to a staging slot first, then swapping, gives zero-downtime releases and instant rollback.

Code example: Deploy an API with OIDC#

YAML.github/workflows/deploy.yml Illustrative
name: deploy-api
on: { push: { branches: [main] } }
permissions: { id-token: write, contents: read }


jobs:
  deploy:
    runs-on: ubuntu-latest
    environment: production            # requires approval if configured
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-dotnet@v4
        with: { dotnet-version: '9.0.x' }
      - run: dotnet test -c Release
      - run: dotnet publish src/Shop.Api -c Release -o ./publish
      - uses: azure/login@v2
        with:
          client-id: ${{ secrets.AZURE_CLIENT_ID }}
          tenant-id: ${{ secrets.AZURE_TENANT_ID }}
          subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
      - uses: azure/webapps-deploy@v3
        with: { app-name: app-shop-api, slot-name: staging, package: ./publish }
      - run: az webapp deployment slot swap -g rg-shop-prod -n app-shop-api --slot staging
Expected output
Tests pass → the build deploys to the staging slot → staging is swapped into production with no downtime.

This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.

Step-by-step explanation#

  1. id-token: write lets the job request an OIDC token.
  2. The three IDs are not secrets in the password sense, but storing them as secrets keeps workflows tidy.
  3. The app deploys to staging first.
  4. Swapping moves the warmed-up staging version into production.

Real-world use case#

Every merged pull request reaches production within minutes, with a human approval gate and instant rollback by swapping back.

Common mistakes#

Using a long-lived client secret

Secrets expire and leak. OIDC federation removes them entirely.

Deploying straight to production

Deploy to a slot, verify, then swap.

Best practices#

  • Use OIDC federation
  • Run tests before deploying
  • Protect production with environment approvals
  • Deploy to slots and swap

Remember this#

OIDC = no secrets in GitHub.

Test → deploy to staging → swap.

Rollback = swap back.

Practice exercise#

Your task: Add a step that checks the staging slot health endpoint before swapping.

Show solution
YAML Illustrative
      - run: curl --fail --retry 5 --retry-delay 5 https://app-shop-api-staging.azurewebsites.net/health

Mini quiz#

CI/CD Pipelines quizMultiple choice Question 1 of 1

Which workflow permission is needed for OIDC login to Azure?

Score so far: 0/0

Want more? Practise all Microsoft Azure MCQs · Microsoft Azure interview questions

My notes#

Saved in this browser.

Progress is saved in this browser. Sign in to sync.