7 Continuous Deployment Using YAML Pipelines
7 Continuous Deployment Using YAML Pipelines
To deploy a build artifact from the pipeline, you need a way to download it from the pipeline to the agent. You
use the DownloadPipelineArtifact@2 task to download artifacts.
This task requires a few inputs. The ones we need here are:
buildType, which specifies whether we want the artifacts from the current build or a specific build. For
now, we want to deploy the current build.
artifact, which specifies the name of the artifact to download. We need this input to specify the name
of the .zip file.
- task: DownloadPipelineArtifact@2
inputs:
buildType: current
artifact: 'drop'
- download: current
artifact: drop
Multi-Stage YAML Pipeline with Jobs (not deployment jobs) – Doesn’t support Approvals and Checks…
trigger:
- none
1
Deccansoft Software Services H.No: 153, A/4, Balamrai, Rasoolpura, Secunderabad-500003 TELANGANA,
NDIA. http://www.deccansoft.com | http://www.bestdotnettraining.com
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Azure DevOps – Deccansoft Software Services CD Using Azure Piplines
stages:
- stage: "Build"
jobs:
- job: "BuildJob"
pool:
vmImage: 'windows-latest'
variables:
buildConfiguration: 'Release'
steps:
- task: DotNetCoreCLI@2
displayName: "Restore Project"
inputs:
command: 'restore'
projects: '**/*.csproj'
- task: DotNetCoreCLI@2
displayName : "Build Project"
inputs:
command: 'build'
projects: '**/*.csproj'
arguments: '-c $(buildConfiguration)'
- task: DotNetCoreCLI@2
displayName : "Build Project"
inputs:
command: 'publish'
publishWebProjects: true
arguments: '-c $(buildConfiguration) -o $(build.artifactstagingdirectory)'
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
2
Deccansoft Software Services H.No: 153, A/4, Balamrai, Rasoolpura, Secunderabad-500003 TELANGANA,
NDIA. http://www.deccansoft.com | http://www.bestdotnettraining.com
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Azure DevOps – Deccansoft Software Services CD Using Azure Piplines
- stage: "DeployToDev"
dependsOn: "Build"
jobs:
- job:
pool:
vmImage: "windows-latest"
steps:
- download: current
artifact: drop
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'Azure Connection'
appType: 'webApp'
WebAppName: 'dssdemo1-dev'
packageForLinux: '$(Pipeline.Workspace)/**/*.zip'
- stage: "DeployToQA"
dependsOn: "DeployToDev"
jobs:
- job:
pool:
vmImage: "windows-latest"
steps:
- download: current
artifact: drop
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'Azure Connection'
appType: 'webApp'
WebAppName: 'dssdemo1-qa'
packageForLinux: '$(Pipeline.Workspace)/**/*.zip'
3
Deccansoft Software Services H.No: 153, A/4, Balamrai, Rasoolpura, Secunderabad-500003 TELANGANA,
NDIA. http://www.deccansoft.com | http://www.bestdotnettraining.com
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Azure DevOps – Deccansoft Software Services CD Using Azure Piplines
- stage: "DeployToProd"
dependsOn: "DeployToQA"
jobs:
- job:
pool:
vmImage: "windows-latest"
steps:
- download: current
artifact: drop
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'Azure Connection'
appType: 'webApp'
WebAppName: 'dssdemo1-prod'
deployToSlotOrASE: true
ResourceGroupName: 'DemoRG'
SlotName: 'staging'
packageForLinux: '$(Pipeline.Workspace)/**/*.zip'
- task: AzureAppServiceManage@0
inputs:
azureSubscription: 'Azure Connection'
Action: 'Swap Slots'
WebAppName: 'dssdemo1-prod'
ResourceGroupName: 'DemoRG'
SourceSlot: 'staging'
4
Deccansoft Software Services H.No: 153, A/4, Balamrai, Rasoolpura, Secunderabad-500003 TELANGANA,
NDIA. http://www.deccansoft.com | http://www.bestdotnettraining.com
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Azure DevOps – Deccansoft Software Services CD Using Azure Piplines
Resources:
While environment at its core is a grouping of resources, the resources themselves represent actual
deployment targets. The Kubernetes resource and virtual machine resource types are currently supported.
Security:
User permissions: Set appropriate user permissions to ensure that the users are pre-authorized to define a
pipeline that targets the environment.
1. Environment Click on top right Security
5
Deccansoft Software Services H.No: 153, A/4, Balamrai, Rasoolpura, Secunderabad-500003 TELANGANA,
NDIA. http://www.deccansoft.com | http://www.bestdotnettraining.com
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Azure DevOps – Deccansoft Software Services CD Using Azure Piplines
2. In the User permissions blade, click on +Add to add a User or group and select a suitable Role.
Pipeline permissions: Pipeline permissions can be used to authorize either all or specific pipelines for
deploying to the environment of concern.
Approvals
You can manually control when a stage should run using approval checks. This is commonly used to control
deployments to production environments.
Checks are a mechanism available to the resource owner to control if and when a stage in a pipeline can
consume a resource. As an owner of a resource, such as an environment, you can define checks that must be
satisfied before a stage consuming that resource can start.
Currently, manual approval checks are supported on environments.
trigger:
- none
stages:
- stage: 'BuildStage'
jobs:
- job: 'BuildJob'
pool:
vmImage: windows-latest
variables:
buildConfiguration: 'Release'
steps:
- task: DotNetCoreCLI@2
displayName: "Restore"
inputs:
command: 'restore'
projects: '**/*.csproj'
feedsToUse: 'select'
- task: DotNetCoreCLI@2
displayName: "Build"
inputs:
command: 'build'
projects: '**/*.csproj'
- task: DotNetCoreCLI@2
6
Deccansoft Software Services H.No: 153, A/4, Balamrai, Rasoolpura, Secunderabad-500003 TELANGANA,
NDIA. http://www.deccansoft.com | http://www.bestdotnettraining.com
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Azure DevOps – Deccansoft Software Services CD Using Azure Piplines
displayName: "Publish"
inputs:
command: 'publish'
publishWebProjects: true
arguments: '--output $(Build.ArtifactStagingDirectory) --configuration $(buildConfiguration)'
- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
artifact: 'drop'
publishLocation: 'pipeline'
- stage: 'DeploytoDev'
dependsOn: 'BuildStage'
jobs:
- deployment:
pool:
vmImage: 'ubuntu-latest'
environment: Development
strategy:
runOnce:
deploy:
steps:
# - task: DownloadPipelineArtifact@2
# inputs:
# buildType: 'current'
# artifactName: 'drop'
# targetPath: '$(Pipeline.Workspace)'
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'VS Subscription - SS1 - Automatic'
appType: 'webApp'
WebAppName: 'dsdemoapp-dev'
packageForLinux: '$(Pipeline.Workspace)/**/*.zip'
- stage: 'DeploytoQA'
7
Deccansoft Software Services H.No: 153, A/4, Balamrai, Rasoolpura, Secunderabad-500003 TELANGANA,
NDIA. http://www.deccansoft.com | http://www.bestdotnettraining.com
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Azure DevOps – Deccansoft Software Services CD Using Azure Piplines
dependsOn: 'DeploytoDev'
jobs:
- deployment:
environment: QA
pool:
vmImage: 'ubuntu-latest'
strategy:
runOnce:
deploy:
steps:
# - task: DownloadPipelineArtifact@2
# inputs:
# buildType: 'current'
# artifactName: 'drop'
# targetPath: '$(Pipeline.Workspace)'
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'VS Subscription - SS1 - Automatic'
appType: 'webApp'
WebAppName: 'dsdemoapp-qa'
packageForLinux: '$(Pipeline.Workspace)/**/*.zip'
- stage: 'DeploytoProd'
dependsOn: 'DeploytoQA'
jobs:
- deployment:
environment: Production
pool:
vmImage: 'ubuntu-latest'
strategy:
runOnce:
deploy:
steps:
# - task: DownloadPipelineArtifact@2
# inputs:
8
Deccansoft Software Services H.No: 153, A/4, Balamrai, Rasoolpura, Secunderabad-500003 TELANGANA,
NDIA. http://www.deccansoft.com | http://www.bestdotnettraining.com
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Azure DevOps – Deccansoft Software Services CD Using Azure Piplines
# buildType: 'current'
# artifactName: 'drop'
# targetPath: '$(Pipeline.Workspace)'
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'VS Subscription - SS1 - Automatic'
appType: 'webApp'
WebAppName: 'dsdemoapp-prod'
deployToSlotOrASE: true
ResourceGroupName: 'Demo-rg'
SlotName: 'staging'
packageForLinux: '$(Pipeline.Workspace)/**/*.zip'
- task: AzureAppServiceManage@0
inputs:
azureSubscription: 'VS Subscription - SS1 - Automatic'
Action: 'Swap Slots'
WebAppName: 'dsdemoapp-prod'
ResourceGroupName: 'Demo-rg'
SourceSlot: 'staging'
Note: Deployment Job doesn’t need to have download task as it is builtin by default.
Use the below Task for Application Settings:
- task: AzureAppServiceSettings@1
inputs:
azureSubscription: 'Azure Connection'
appName: 'dsshellowebapp'
resourceGroupName: 'Demo-rg'
slotName: 'staging'
appSettings: |
[
{
"name": "key1",
"value": "valueabcd",
"slotSetting": false
},
9
Deccansoft Software Services H.No: 153, A/4, Balamrai, Rasoolpura, Secunderabad-500003 TELANGANA,
NDIA. http://www.deccansoft.com | http://www.bestdotnettraining.com
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Azure DevOps – Deccansoft Software Services CD Using Azure Piplines
{
"name": "key2",
"value": "valueefgh",
"slotSetting": true
}
]
stages:
- stage: 'Build'
displayName: 'Build the web application'
jobs:
- job: Build
10
Deccansoft Software Services H.No: 153, A/4, Balamrai, Rasoolpura, Secunderabad-500003 TELANGANA,
NDIA. http://www.deccansoft.com | http://www.bestdotnettraining.com
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Azure DevOps – Deccansoft Software Services CD Using Azure Piplines
steps:
- task: DotNetCoreCLI@2
displayName: 'Restore project dependencies'
inputs:
command: 'restore'
projects: '**/*.csproj'
- task: DotNetCoreCLI@2
displayName: 'Build the project - $(buildConfiguration)'
inputs:
command: 'build'
arguments: '--no-restore --configuration $(buildConfiguration)'
projects: '**/*.csproj'
- task: DotNetCoreCLI@2
displayName: 'Publish the project - $(buildConfiguration)'
inputs:
command: 'publish'
projects: '**/*.csproj'
publishWebProjects: false
arguments: '--no-build --configuration $(buildConfiguration) --
output $(Build.ArtifactStagingDirectory)/$(buildConfiguration)'
zipAfterPublish: true
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: drop'
condition: succeeded()
- stage: 'Deploy'
11
Deccansoft Software Services H.No: 153, A/4, Balamrai, Rasoolpura, Secunderabad-500003 TELANGANA,
NDIA. http://www.deccansoft.com | http://www.bestdotnettraining.com
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Azure DevOps – Deccansoft Software Services CD Using Azure Piplines
- task: IISWebAppDeploymentOnMachineGroup@0
inputs:
WebSiteName: 'default web site'
Package: '$(Pipeline.Workspace)/**/*.zip'
TakeAppOfflineFlag: true
7. Save and Run the Pipeline
8. View History: Environment Click WebServers Deployments
12
Deccansoft Software Services H.No: 153, A/4, Balamrai, Rasoolpura, Secunderabad-500003 TELANGANA,
NDIA. http://www.deccansoft.com | http://www.bestdotnettraining.com
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Azure DevOps – Deccansoft Software Services CD Using Azure Piplines
YAML for Deploying to respective Environment Based on Which Branch Build was Performed.
trigger:
- master
- development
- release
- hotfix
variables:
AzureConnection: 'Azure Pass 2'
stages:
- stage: "Build_Stage"
displayName: "Building the web application"
jobs:
- job: 'Build_Job'
displayName: "Job: Building the application"
pool:
vmImage: 'ubuntu-latest'
variables:
buildConfiguration: 'Release'
ProjectName: '**/*.csproj'
steps:
- task: DotNetCoreCLI@2
displayName: Restore
inputs:
command: 'restore'
projects: '$(ProjectName)'
feedsToUse: 'select'
- task: DotNetCoreCLI@2
displayName: 'Build Step'
inputs:
command: 'build'
projects: '$(ProjectName)'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI@2
13
Deccansoft Software Services H.No: 153, A/4, Balamrai, Rasoolpura, Secunderabad-500003 TELANGANA,
NDIA. http://www.deccansoft.com | http://www.bestdotnettraining.com
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Azure DevOps – Deccansoft Software Services CD Using Azure Piplines
inputs:
command: 'publish'
publishWebProjects: true
arguments: '--configuration $(buildConfiguration) -o $(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
- stage: "DeployToDev_Stage"
dependsOn: Build_Stage
condition: eq(variables['Build.SourceBranch'], 'refs/heads/development')
jobs:
- deployment: 'DeployToDev'
displayName: "Job: Deploying to Dev Stage"
pool:
vmImage: 'ubuntu-latest'
environment: dev
strategy:
runOnce:
deploy:
steps:
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: $(AzureConnection)
appType: 'webApp'
WebAppName: 'dssdemoapp-dev'
packageForLinux: '$(Pipeline.Workspace)/**/*.zip'
- stage: "DeployToQA_Stage"
dependsOn: Build_Stage
condition: eq(variables['Build.SourceBranch'], 'refs/heads/release')
jobs:
- deployment: 'DeployToQA_Job'
14
Deccansoft Software Services H.No: 153, A/4, Balamrai, Rasoolpura, Secunderabad-500003 TELANGANA,
NDIA. http://www.deccansoft.com | http://www.bestdotnettraining.com
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Azure DevOps – Deccansoft Software Services CD Using Azure Piplines
- stage: "DeployToProd_Stage"
dependsOn: Build_Stage
condition: eq(variables['Build.SourceBranch'], 'refs/heads/master')
jobs:
- deployment: 'DeployToProd_Job'
displayName: "Job: Deploying to Prod Stage"
pool:
vmImage: 'ubuntu-latest'
environment: Prod
strategy:
runOnce:
deploy:
steps:
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: '$(AzureConnection)'
appType: 'webApp'
WebAppName: 'dssdemoapp-prod'
deployToSlotOrASE: true
15
Deccansoft Software Services H.No: 153, A/4, Balamrai, Rasoolpura, Secunderabad-500003 TELANGANA,
NDIA. http://www.deccansoft.com | http://www.bestdotnettraining.com
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Azure DevOps – Deccansoft Software Services CD Using Azure Piplines
ResourceGroupName: 'SandeepRG'
SlotName: 'staging'
packageForLinux: '$(Pipeline.Workspace)/**/*.zip'
- task: AzureAppServiceManage@0
inputs:
azureSubscription: $(AzureConnection)
Action: 'Swap Slots'
WebAppName: 'dssdemoapp-prod'
ResourceGroupName: 'SandeepRG'
SourceSlot: 'staging'
stages:
- stage: 'Build'
displayName: 'Build the web application'
jobs:
- job: Build
displayName: 'Build Job'
pool:
vmImage: 'ubuntu-16.04'
variables:
dotnetSdkVersion: '3.1.x'
steps:
- task: DotNetCoreCLI@2
16
Deccansoft Software Services H.No: 153, A/4, Balamrai, Rasoolpura, Secunderabad-500003 TELANGANA,
NDIA. http://www.deccansoft.com | http://www.bestdotnettraining.com
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Azure DevOps – Deccansoft Software Services CD Using Azure Piplines
- task: DotNetCoreCLI@2
displayName: 'Build the project - $(buildConfiguration)'
inputs:
command: 'build'
arguments: '--no-restore --configuration $(buildConfiguration)'
projects: '**/*.csproj'
- task: DotNetCoreCLI@2
displayName: 'Publish the project - $(buildConfiguration)'
inputs:
command: 'publish'
projects: '**/*.csproj'
publishWebProjects: false
arguments: '--no-build --configuration $(buildConfiguration) --
output $(Build.ArtifactStagingDirectory)/$(buildConfiguration)'
zipAfterPublish: true
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: drop'
condition: succeeded()
- stage: 'Deploy'
displayName: 'Deploy the azure Function'
dependsOn: Build
variables:
appName: dssdemoafunc123
azureSubscription: 'Azure Subscription Connection'
jobs:
- deployment: Deploy
pool:
vmImage: 'windows-latest'
17
Deccansoft Software Services H.No: 153, A/4, Balamrai, Rasoolpura, Secunderabad-500003 TELANGANA,
NDIA. http://www.deccansoft.com | http://www.bestdotnettraining.com
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)
Azure DevOps – Deccansoft Software Services CD Using Azure Piplines
environment: 'Azure-function'
strategy:
runOnce:
deploy:
steps:
- task: AzureFunctionApp@1
displayName: Azure Function App Deploy
inputs:
azureSubscription: 'Azure Subscription Connection'
appType: 'functionAppLinux'
appName: '$(appName)'
package: '$(Pipeline.Workspace)/drop/$(buildConfiguration)/*.zip'
18
Deccansoft Software Services H.No: 153, A/4, Balamrai, Rasoolpura, Secunderabad-500003 TELANGANA,
NDIA. http://www.deccansoft.com | http://www.bestdotnettraining.com
Phone: +91 40 2784 1517 OR +91 8008327000 (INDIA)