Skip to content
Latchkey

How to Create and Use Service Connections in Azure Pipelines

A service connection stores credentials for an external service so tasks can authenticate without hardcoded secrets.

Create the connection under Project Settings > Service connections, then reference it by name from tasks (e.g. azureSubscription, containerRegistry).

Reference an Azure service connection

The AzureCLI task uses the named connection to authenticate against the subscription.

azure-pipelines.yml
steps:
  - task: AzureCLI@2
    inputs:
      azureSubscription: 'prod-azure-conn'
      scriptType: bash
      scriptLocation: inlineScript
      inlineScript: az webapp list -o table

Gotchas

  • Prefer a workload identity / federated service connection over a long-lived secret-based one.
  • Service connections are project-scoped by default; share them across projects explicitly if needed.
  • A connection can require approval on first use by a new pipeline - grant access in its security settings.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →