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
This document provides a reference for commonly used built-in Azure Pipelines tasks.
- task: TaskName@MajorVersion
displayName: 'Human Readable Name'
inputs:
inputName: value
anotherInput: value
condition: succeeded()
continueOnError: false
enabled: true
env:
ENV_VAR: value
timeoutInMinutes: 0Build, test, package, or publish a .NET Core project.
- task: DotNetCoreCLI@2
displayName: 'Restore NuGet packages'
inputs:
command: 'restore'
projects: '**/*.csproj'
- task: DotNetCoreCLI@2
displayName: 'Build'
inputs:
command: 'build'
projects: '**/*.csproj'
arguments: '--configuration Release'
- task: DotNetCoreCLI@2
displayName: 'Run Tests'
inputs:
command: 'test'
projects: '**/*Tests/*.csproj'
arguments: '--configuration Release --collect:"XPlat Code Coverage"'
- task: DotNetCoreCLI@2
displayName: 'Publish'
inputs:
command: 'publish'
projects: '**/*.csproj'
arguments: '--configuration Release --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: trueRestore, pack, or push NuGet packages.
- task: NuGetCommand@2
displayName: 'NuGet restore'
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
- task: NuGetCommand@2
displayName: 'NuGet pack'
inputs:
command: 'pack'
packagesToPack: '**/*.nuspec'
versioningScheme: 'byBuildNumber'Install a specific Node.js version.
- task: NodeTool@0
displayName: 'Use Node.js 20.x'
inputs:
versionSpec: '20.x'Run npm commands.
- task: Npm@1
displayName: 'npm install'
inputs:
command: 'install'
- task: Npm@1
displayName: 'npm run build'
inputs:
command: 'custom'
customCommand: 'run build'
- task: Npm@1
displayName: 'npm test'
inputs:
command: 'custom'
customCommand: 'run test'Select a Python version to run on an agent.
- task: UsePythonVersion@0
displayName: 'Use Python 3.11'
inputs:
versionSpec: '3.11'
addToPath: true
architecture: 'x64'Install Python packages.
- script: |
python -m pip install --upgrade pip
pip install -r requirements.txt
displayName: 'Install dependencies'
- script: pytest tests/ --junitxml=junit/test-results.xml
displayName: 'Run tests'Build, push, or run Docker images.
# Login to registry
- task: Docker@2
displayName: 'Docker Login'
inputs:
command: 'login'
containerRegistry: 'myDockerRegistryServiceConnection'
# Build image
- task: Docker@2
displayName: 'Build Docker image'
inputs:
command: 'build'
repository: 'myrepo/myimage'
dockerfile: '$(Build.SourcesDirectory)/Dockerfile'
tags: |
$(Build.BuildId)
latest
# Push image
- task: Docker@2
displayName: 'Push Docker image'
inputs:
command: 'push'
repository: 'myrepo/myimage'
tags: |
$(Build.BuildId)
latest
# Build and push (combined)
- task: Docker@2
displayName: 'Build and Push'
inputs:
command: 'buildAndPush'
repository: 'myrepo/myimage'
dockerfile: '$(Build.SourcesDirectory)/Dockerfile'
containerRegistry: 'myDockerRegistryServiceConnection'
tags: |
$(Build.BuildId)
latestBuild, push, or run multi-container Docker applications.
- task: DockerCompose@0
displayName: 'Run Docker Compose'
inputs:
action: 'Run services'
dockerComposeFile: 'docker-compose.yml'
projectName: '$(Build.Repository.Name)'
qualifyImageNames: true
buildImages: trueDeploy, configure, or update a Kubernetes cluster.
- task: Kubernetes@1
displayName: 'kubectl apply'
inputs:
connectionType: 'Kubernetes Service Connection'
kubernetesServiceEndpoint: 'myK8sConnection'
command: 'apply'
arguments: '-f manifests/'
- task: Kubernetes@1
displayName: 'kubectl set image'
inputs:
connectionType: 'Kubernetes Service Connection'
kubernetesServiceEndpoint: 'myK8sConnection'
command: 'set'
arguments: 'image deployment/myapp myapp=$(containerRegistry)/myimage:$(Build.BuildId)'Bake and deploy Kubernetes manifests.
- task: KubernetesManifest@0
displayName: 'Deploy to Kubernetes'
inputs:
action: 'deploy'
kubernetesServiceConnection: 'myK8sConnection'
namespace: 'production'
manifests: |
manifests/deployment.yml
manifests/service.yml
containers: '$(containerRegistry)/myimage:$(Build.BuildId)'Deploy using Helm charts.
- task: HelmDeploy@0
displayName: 'Helm deploy'
inputs:
connectionType: 'Kubernetes Service Connection'
kubernetesServiceConnection: 'myK8sConnection'
namespace: 'production'
command: 'upgrade'
chartType: 'FilePath'
chartPath: '$(Build.SourcesDirectory)/charts/myapp'
releaseName: 'myapp'
arguments: '--set image.tag=$(Build.BuildId)'Run Azure CLI commands.
- task: AzureCLI@2
displayName: 'Azure CLI'
inputs:
azureSubscription: 'myAzureServiceConnection'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
az --version
az account showRun Azure PowerShell commands.
- task: AzurePowerShell@5
displayName: 'Azure PowerShell'
inputs:
azureSubscription: 'myAzureServiceConnection'
scriptType: 'inlineScript'
inline: |
Get-AzResourceGroup
azurePowerShellVersion: 'LatestVersion'Deploy to Azure App Service.
- task: AzureWebApp@1
displayName: 'Deploy to Azure Web App'
inputs:
azureSubscription: 'myAzureServiceConnection'
appType: 'webAppLinux'
appName: 'mywebapp'
package: '$(Build.ArtifactStagingDirectory)/**/*.zip'Deploy to Azure Functions.
- task: AzureFunctionApp@1
displayName: 'Deploy Azure Function'
inputs:
azureSubscription: 'myAzureServiceConnection'
appType: 'functionAppLinux'
appName: 'myfunctionapp'
package: '$(Build.ArtifactStagingDirectory)/**/*.zip'Advanced Azure App Service deployment.
- task: AzureRmWebAppDeployment@4
displayName: 'Azure App Service Deploy'
inputs:
azureSubscription: 'myAzureServiceConnection'
appType: 'webAppLinux'
WebAppName: 'mywebapp'
packageForLinux: '$(Build.ArtifactStagingDirectory)/**/*.zip'
RuntimeStack: 'NODE|20-lts'Publish build artifacts to Azure Pipelines.
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: drop'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'Download build artifacts.
- task: DownloadBuildArtifacts@1
displayName: 'Download Build Artifacts'
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'drop'
downloadPath: '$(System.ArtifactsDirectory)'Publish artifacts (preferred over PublishBuildArtifacts).
- task: PublishPipelineArtifact@1
displayName: 'Publish Pipeline Artifact'
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
artifact: 'drop'
publishLocation: 'pipeline'Download pipeline artifacts (preferred over DownloadBuildArtifacts).
- task: DownloadPipelineArtifact@2
displayName: 'Download Pipeline Artifact'
inputs:
buildType: 'current'
artifactName: 'drop'
targetPath: '$(Pipeline.Workspace)'Publish test results.
- task: PublishTestResults@2
displayName: 'Publish Test Results'
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '**/test-results.xml'
searchFolder: '$(System.DefaultWorkingDirectory)'
mergeTestResults: true
failTaskOnFailedTests: truePublish code coverage results.
- task: PublishCodeCoverageResults@1
displayName: 'Publish Code Coverage'
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.xml'
reportDirectory: '$(System.DefaultWorkingDirectory)/**/htmlcov'Copy files to a target folder.
- task: CopyFiles@2
displayName: 'Copy Files'
inputs:
SourceFolder: '$(Build.SourcesDirectory)'
Contents: |
**/*.js
**/*.json
!node_modules/**
TargetFolder: '$(Build.ArtifactStagingDirectory)'
CleanTargetFolder: trueDelete files from the agent.
- task: DeleteFiles@1
displayName: 'Delete Files'
inputs:
SourceFolder: '$(Build.SourcesDirectory)'
Contents: |
**/node_modules
**/tempCache files and restore them in future runs.
- task: Cache@2
displayName: 'Cache npm'
inputs:
key: 'npm | "$(Agent.OS)" | package-lock.json'
restoreKeys: |
npm | "$(Agent.OS)"
path: $(Pipeline.Workspace)/.npm
- task: Cache@2
displayName: 'Cache Maven'
inputs:
key: 'maven | "$(Agent.OS)" | **/pom.xml'
restoreKeys: |
maven | "$(Agent.OS)"
path: $(Pipeline.Workspace)/.m2/repositoryRun PowerShell or Bash scripts.
- task: PowerShell@2
displayName: 'Run PowerShell Script'
inputs:
targetType: 'inline'
script: |
Write-Host "Running PowerShell"
Get-ChildItem -Path $(Build.SourcesDirectory)
- task: Bash@3
displayName: 'Run Bash Script'
inputs:
targetType: 'inline'
script: |
echo "Running Bash"
ls -la $(Build.SourcesDirectory)SonarCloud code analysis.
- task: SonarCloudPrepare@1
inputs:
SonarCloud: 'SonarCloud'
organization: 'myorg'
scannerMode: 'CLI'
configMode: 'manual'
cliProjectKey: 'myproject'
cliProjectName: 'My Project'
- task: SonarCloudAnalyze@1
displayName: 'Run SonarCloud Analysis'
- task: SonarCloudPublish@1
displayName: 'Publish SonarCloud Results'
inputs:
pollingTimeoutSec: '300'WhiteSource security and license scanning.
- task: WhiteSource@21
inputs:
cwd: '$(Build.SourcesDirectory)'
projectName: 'MyProject'Create a GitHub release.
- task: GitHubRelease@1
displayName: 'Create GitHub Release'
inputs:
gitHubConnection: 'GitHubServiceConnection'
repositoryName: '$(Build.Repository.Name)'
action: 'create'
target: '$(Build.SourceVersion)'
tagSource: 'gitTag'
tag: '$(Build.BuildNumber)'
title: 'Release $(Build.BuildNumber)'
releaseNotesSource: 'inline'
releaseNotesInline: 'Release notes here'
assets: '$(Build.ArtifactStagingDirectory)/**'@2, not @0)For detailed task documentation:
Tasks follow semantic versioning:
# Major version (recommended)
- task: TaskName@2
# Full version (for specific fixes)
- task: TaskName@2.3.1Always use the latest major version unless you have specific compatibility requirements.
You can also create and use custom tasks from:
# Marketplace task
- task: PublisherName.ExtensionName.TaskName@version
# Template as reusable task
- template: templates/my-custom-task.yml
parameters:
parameter1: value