Azure-DevOps
Azure DevOps Pipeline Syntax Cheat Sheet
Variables
variables:
variable1: "value1"
variable2: "value2"
Stages
stages:
- stage: Stage1
jobs:
- job: Job1
steps:
- script: echo "Hello, World!"
Jobs
jobs:
- job: Job1
displayName: "Job 1"
dependsOn: Job2
steps:
- script: echo "Hello, World!"
- task: Task1@1
inputs:
parameter1: "value1"
parameter2: "value2"
Steps
steps:
- script: echo "Hello, World!"
- task: Task1@1
inputs:
parameter1: "value1"
parameter2: "value2"
Tasks
steps:
- task: Task1@1
inputs:
parameter1: "value1"
parameter2: "value2"
Conditionals
steps:
- script: echo "Hello, World!"
condition: eq(variable1, 'value1')
Loops
steps:
- script: echo ${{ each value in variables.variableArray }}'Value: ${{ value }}'${{ if ne(value, last(variables.variableArray)) }}; {{ else }}.{{ endif }}
Artifacts
- publish: $(System.DefaultWorkingDirectory)/artifact
artifact: myArtifact
Trigger
trigger:
- master
- releases/*
- feature/*
Prerequisites
prerequisites:
- pipeline: Pipeline1
source: SourcePipeline
trigger:
branches:
- master
Resources
resources:
- repo: self
clean: true
- repo: some/other-repo
clean: true
Templates
resources:
repositories:
- repository: templates
type: git
name: MyTemplates
ref: refs/tags/v1
- repository: scripts
type: git
name: MyScripts
ref: refs/tags/v1
- repository: tools
type: git
name: MyTools
ref: refs/tags/v1
- repository: packages
type: git
name: MyPackages
ref: refs/tags/v1
Environments
environments:
- name: Dev
resource:
type: environment
name: DevEnvironment
conditions:
- and:
- eq(variables['Build.SourceBranch'], 'refs/heads/master')
- eq(variables['Build.Reason'], 'IndividualCI')
Azure DevOps CLI
Install Azure DevOps CLI
az extension add --name azure-devops
Log in to Azure DevOps
az devops configure --defaults organization=<ORGANIZATION_URL> project=<PROJECT_NAME>
Azure DevOps commands
Create a new Azure DevOps project
az devops project create --name <PROJECT_NAME>
az devops project show --project <PROJECT_NAME>
List all Azure DevOps projects
Create a new Azure DevOps service connection
az devops service-endpoint create \
--name <SERVICE_CONNECTION_NAME> \
--type <SERVICE_CONNECTION_TYPE> \
--url <SERVICE_CONNECTION_URL> \
--authorization-scheme <AUTHORIZATION_SCHEME> \
--project <PROJECT_NAME>
Update an existing Azure DevOps service connection
az devops service-endpoint update \
--id <SERVICE_CONNECTION_ID> \
--name <NEW_SERVICE_CONNECTION_NAME>
Delete an Azure DevOps service connection
az devops service-endpoint delete \
--id <SERVICE_CONNECTION_ID>
List all Azure DevOps service connections
az devops service-endpoint list
Create a new Azure DevOps pipeline
az pipelines create \
--name <PIPELINE_NAME> \
--description <PIPELINE_DESCRIPTION> \
--repository <REPOSITORY_URL> \
--branch <BRANCH_NAME> \
--yml-path <YAML_PATH> \
--skip-first-run \
--project <PROJECT_NAME>
Update an existing Azure DevOps pipeline
az pipelines update \
--id <PIPELINE_ID> \
--name <NEW_PIPELINE_NAME>
Delete an Azure DevOps pipeline
az pipelines delete \
--id <PIPELINE_ID>
List all Azure DevOps pipelines
Create a new Azure DevOps variable group
az pipelines variable-group create \
--name <VARIABLE_GROUP_NAME> \
--variables <VARIABLES_JSON> \
--project <PROJECT_NAME>
Update an existing Azure DevOps variable group
az pipelines variable-group update \
--id <VARIABLE_GROUP_ID> \
--name <NEW_VARIABLE_GROUP_NAME>
Delete an Azure DevOps variable group
az pipelines variable-group delete \
--id <VARIABLE_GROUP_ID>
List all Azure DevOps variable groups
az pipelines variable-group list
Trigger an Azure DevOps pipeline
az pipelines run \
--id <PIPELINE_ID> \
--branch <BRANCH_NAME> \
--variables <VARIABLES_JSON>
Get the status of an Azure DevOps pipeline run
az pipelines runs show \
--id <PIPELINE_RUN_ID>
List all Azure DevOps pipeline runs