Complete azure-pipelines toolkit with generation and validation capabilities
97
97%
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Advisory
Suggest reviewing before use
Comprehensive reference for Azure Pipelines YAML syntax and structure.
Azure Pipelines supports three main structures:
stages:
- stage: Build
jobs:
- job: BuildJob
steps:
- script: echo "Building"jobs:
- job: Job1
steps:
- script: echo "Job 1"
- job: Job2
steps:
- script: echo "Job 2"steps:
- script: echo "Single job"Defines CI triggers (push events):
trigger:
branches:
include:
- main
- develop
paths:
exclude:
- docs/*Defines PR triggers:
pr:
branches:
include:
- main
paths:
include:
- src/*Defines scheduled triggers:
schedules:
- cron: "0 0 * * *"
displayName: Daily midnight build
branches:
include:
- mainDefines agent pool:
pool:
vmImage: 'ubuntu-22.04'
demands:
- npmOr use specific pool:
pool:
name: 'My Agent Pool'Defines variables:
variables:
configuration: 'Release'
platform: 'x64'Or variable groups:
variables:
- group: 'my-variable-group'
- name: myVar
value: myValueDefines external resources:
resources:
repositories:
- repository: templates
type: git
name: MyProject/Templates
pipelines:
- pipeline: upstream
source: UpstreamPipeline
trigger: true
containers:
- container: linux
image: ubuntu:22.04stages:
- stage: StageName
displayName: 'Stage Display Name'
dependsOn: PreviousStage
condition: succeeded()
variables:
stageVar: value
jobs:
- job: JobName
steps:
- script: echo "Hello"jobs:
- job: JobName
displayName: 'Job Display Name'
dependsOn: PreviousJob
condition: succeeded()
timeoutInMinutes: 60
cancelTimeoutInMinutes: 5
pool:
vmImage: 'ubuntu-22.04'
variables:
jobVar: value
steps:
- script: echo "Job step"jobs:
- deployment: DeploymentName
displayName: 'Deploy to Environment'
environment: 'production'
pool:
vmImage: 'ubuntu-22.04'
strategy:
runOnce:
deploy:
steps:
- script: echo "Deploying"strategy:
runOnce:
preDeploy:
steps:
- script: echo "Pre-deploy"
deploy:
steps:
- script: echo "Deploy"
routeTraffic:
steps:
- script: echo "Route traffic"
postRouteTraffic:
steps:
- script: echo "Post-route"
on:
failure:
steps:
- script: echo "Rollback"
success:
steps:
- script: echo "Success"strategy:
rolling:
maxParallel: 2
deploy:
steps:
- script: echo "Deploy to rolling targets"strategy:
canary:
increments: [10, 20, 50]
deploy:
steps:
- script: echo "Deploy canary"Executes a pipeline task:
- task: TaskName@MajorVersion
displayName: 'Task Display Name'
inputs:
input1: value1
input2: value2
env:
ENV_VAR: value
condition: succeeded()
continueOnError: false
timeoutInMinutes: 10Runs a shell script:
- script: |
echo "Multi-line"
echo "script"
displayName: 'Run Script'
workingDirectory: $(Build.SourcesDirectory)
failOnStderr: falseRuns a bash script:
- bash: |
#!/bin/bash
echo "Bash script"
displayName: 'Bash Script'Runs PowerShell:
- pwsh: |
Write-Host "PowerShell Core"
displayName: 'PowerShell Script'
- powershell: |
Write-Host "Windows PowerShell"
displayName: 'Windows PowerShell'Checks out repositories:
- checkout: self
clean: true
fetchDepth: 1
lfs: false
submodules: false
persistCredentials: falseDownloads artifacts:
- download: current
artifact: artifactNamePublishes artifacts:
- publish: $(Build.ArtifactStagingDirectory)
artifact: dropReferences a template:
- template: templates/build-steps.yml
parameters:
param1: value1- task: Npm@1
inputs:
command: 'install' # or 'ci', 'custom'
workingDir: '$(System.DefaultWorkingDirectory)'
customCommand: 'run build'- task: DotNetCoreCLI@2
inputs:
command: 'build' # or 'restore', 'test', 'publish'
projects: '**/*.csproj'
arguments: '--configuration Release'- task: Docker@2
inputs:
command: 'build' # or 'push', 'login'
repository: 'myrepo/myimage'
dockerfile: '$(Build.SourcesDirectory)/Dockerfile'
tags: |
$(Build.BuildId)
latest- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
artifact: 'drop'
publishLocation: 'pipeline'- task: AzureWebApp@1
inputs:
azureSubscription: 'Azure-Connection'
appName: 'mywebapp'
package: '$(System.DefaultWorkingDirectory)/**/*.zip'# Always run
condition: always()
# Run on success
condition: succeeded()
# Run on failure
condition: failed()
# Run on success or failure
condition: succeededOrFailed()
# Custom condition
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))# Pipeline variable
$(variableName)
# Environment variable (bash)
$VARIABLE_NAME
# Environment variable (PowerShell)
$env:VARIABLE_NAME
# Runtime expression
${{ variables.variableName }}
# Predefined variables
$(Build.BuildId)
$(Build.SourceBranch)
$(Agent.OS)
$(System.DefaultWorkingDirectory)# variables/common.yml
variables:
configuration: 'Release'
platform: 'x64'# templates/build-steps.yml
parameters:
- name: buildConfiguration
type: string
default: 'Release'
steps:
- script: echo "Building with ${{ parameters.buildConfiguration }}"# templates/test-job.yml
parameters:
- name: jobName
type: string
- name: pool
type: string
jobs:
- job: ${{ parameters.jobName }}
pool:
vmImage: ${{ parameters.pool }}
steps:
- script: echo "Testing"TaskName@2 not TaskName@*ubuntu-22.04 not ubuntu-latesttimeoutInMinutesclean: true for consistent builds