Instruction file imported from soofoove/copilot-knowledge (
.github/instructions/azure-devops-pipelines.instructions.md). Copyright stays with the author.
Reviewed Azure DevOps Pipelines Guidance
Pipeline Structure
- Use YAML pipelines over classic (UI) pipelines for version control and review.
- Prefer multi-stage pipelines (
stages→jobs→steps) for clear separation of build, test, and deploy. - Use
triggerandprsections explicitly; avoid relying on default triggers. - Set
poolat the pipeline or stage level; prefervmImage: 'ubuntu-latest'unless Windows-specific.
Templates and Reuse
- Extract repeated logic into templates (
templatereferences) stored in a shared folder. - Use
parameterswith types and defaults in templates for type safety. - Prefer
extendstemplates for enforcing pipeline patterns across teams. - Use template expressions (
${{ }}) for compile-time logic; use runtime expressions ($[ ]) only when values are not known until runtime.
Security
- Never hardcode secrets, tokens, or connection strings in pipeline YAML.
- Use variable groups and Azure Key Vault integration for secrets.
- Mark secret variables as
isSecret: trueor use thesecrettype in variable groups. - Use service connections with least-privilege access; prefer Workload Identity Federation over secrets.
- Set
checkout: selfwithfetchDepth: 1for shallow clones unless full history is needed. - Use
permissionsand branch policies to restrict who can modify pipelines.
Variables and Parameters
- Define variables at the top of the pipeline or in variable groups for reuse.
- Use
parametersfor user-facing inputs with definedtype,default, andvalues. - Prefer
variablestemplates for shared variable sets across pipelines. - Avoid
$(System.AccessToken)in scripts; useenvmapping instead.
.NET Build Steps
- Run
dotnet restore,dotnet build, anddotnet testas separate steps for clear failure diagnostics. - Use
DotNetCoreCLI@2task or inlinedotnetscript steps. - Cache NuGet packages with the
Cache@2task using$(NUGET_PACKAGES)or~/.nuget/packagesas the path. - Publish test results with
PublishTestResults@2and code coverage withPublishCodeCoverageResults@2. - Use
--configuration Releasefor build and publish steps in non-dev stages.
Artifacts and Deployment
- Use
PublishPipelineArtifact@1andDownloadPipelineArtifact@2over the olderPublishBuildArtifacts. - Name artifacts descriptively (e.g.,
drop-api,drop-web). - Use environments with approval gates and checks for production deployments.
- Prefer deployment jobs (
deployment) with strategies (runOnce,canary,rolling) over plain jobs for deploy stages.
Quality and Maintainability
- Add
displayNameto every step and job for readable logs. - Use
conditionto control step execution; prefersucceeded(),failed(),always()over custom expressions when possible. - Use
dependsOnandconditionfor stage and job orchestration. - Set
timeoutInMinuteson long-running jobs to prevent runaway pipelines. - Use
continueOnError: false(the default) to fail fast on errors.