Published on

Azure DevOps Cheatsheet

  • avatar
    Dadi Zhao

Cache your npm/NuGet packages with Pipeline Caching

- task: Cache@2
  displayName: Cache npm Packages
  inputs:    key: 'npm| "$(Agent.OS)" | **/packages.lock.json'    restoreKeys: |      nuget | "$(Agent.OS)"    path: $(NPM_PACKAGES)  #custom defined variable

Use Condition for Tasks

#e.g Do Not Run if triggered by PRcondition: and(succeeded(), ne(variables[‘Build.Reason’], ‘PullRequest’))

Organize your pipeline YAML files

# sample folder structureazure-pipelines
  - job-build.yml
  - job-deploy.yml
  - pipeline-prod.yml
  - pipeline-qa.yml
  - pipeline-uat.yml
  - vars.yml
  - #project source code etc

Use -template to share .yml in other files

# pipeline-qa.ymlvariables:  - template: vars.yml
jobs:  - template: job-build.yml
# also works for stage, step etc

Pass parameters to other .yml files

# pipeline-qa.ymljobs:  - template: job-deploy.yml
    parameters:      environmentName: QA
      environmentTags: qa,website
# job-deploy.ymlparameters:  environmentName: ''  environmentTags: ''jobs:  - deployment: Deployment
  pool:    vmImage: 'windows-latest'  environment:    name: '${{ parameters.environmentName }}'    tags: '${{ parameters.environmentTags }}'  strategy:#deployment tasks etc