Skip to content

Instantly share code, notes, and snippets.

@papeMK2
Created August 25, 2022 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save papeMK2/91477bf1a2df9fee752bc110c9fd20c8 to your computer and use it in GitHub Desktop.
Save papeMK2/91477bf1a2df9fee752bc110c9fd20c8 to your computer and use it in GitHub Desktop.
PullRequest With App Service staging slot
trigger:
branches:
include:
- master
pr:
- master
pool:
vmImage: ubuntu-latest
variables:
buildConfiguration: 'Release'
workingDirectory: '$(System.DefaultWorkingDirectory)/src/MVCApp/'
prId: $(System.PullRequest.PullRequestId)
stages:
- stage: Build
displayName: Build app
jobs:
- job: Build
displayName: Build
steps:
- task: DotNetCoreCLI@2
displayName: Restore
inputs:
command: restore
projects: $(workingDirectory)/*.csproj
- task: DotNetCoreCLI@2
displayName: Build
inputs:
command: 'build'
projects: |
$(workingDirectory)/*.csproj
arguments: --output $(System.DefaultWorkingDirectory)/publish_output --configuration Release
- task: DotNetCoreCLI@2
displayName: Publish
inputs:
command: publish
publishWebProjects: false
projects: $(workingDirectory)/*.csproj
arguments: '--configuration Release --output $(System.DefaultWorkingDirectory)/publish'
zipAfterPublish: true
- publish: '$(System.DefaultWorkingDirectory)/publish'
artifact: drop
- stage: Create_Slot
displayName: Create Pull Request Env
dependsOn: Build
condition: and(succeeded(), eq(variables['Build.Reason'], 'PullRequest'))
jobs:
- job: CreateSlot
displayName: CreateSlot
steps:
- task: AzureCLI@2
inputs:
azureSubscription: '{Your Service Connection Name}'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
az deployment group create --resource-group rg-lab --template-file {Bicep file path for create slot} \
--parameters prId=$(prId) \
--parameters appServiceName=app-appservice-lab
- download: current
artifact: drop
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: '{Your Service Connection Name}'
appType: 'webApp'
WebAppName: 'app-appservice-lab'
deployToSlotOrASE: true
ResourceGroupName: 'rg-lab'
SlotName: 'pr-$(prId)'
packageForLinux: '$(Pipeline.Workspace)/drop/MVCApp.zip'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment