JeanCarloDeCastro
JeanCarloDeCastro

Reputation: 23

Create App Service or Slot with Powershell

I'm configuring my CI/CD pipelines on azure devops. Our main purpose is to automaticalle create an environment for each Pull Request so our QA team can test the change before sending the ticket to code review.

I have an azure build pipelines that triggers a release pipeline when build is complete. My release pipeline execute the following stages:

  1. Stage 1: Create App Service Slot
  2. Stage 2: Deploy to App Service Slot Created on Stage 1

My question is based on Stage 2:

MY CURRENT PROCESS:

I'm currently creating a slot on a specific app service in order to deploy the application to that slot and my QA team can test this feature before code review. I'm using an Azure CLI command to do this. I have encountered a problem and need to change this approach since I didn't know I have a 20 slots limit per app service.

WHAT I NEED TO DO:

I need to configure my release pipeline stage 2 to automatically get all app services with a specific tag, validate if the slots limit have been reached; if slot limit have been reached I need to create a new app service, if the slots limit haven't been reached then I need to create a slot. I've been searching online and apparently I can accomplish this with Powershell. This are the steps I need to complete using Powershell:

  1. Get list of app services with a specific tag
  2. Loop through each app service. On each iteration I need to:
    • Get current slots quantity for this specific app service
    • If slot quantity is below 20, create a new slot and break the iteration
    • If slot quantity is equal to 20, continue to next iteration
    • If all iterations have been completed and no slot have been created, I need to create a new app service

How can we accomplish this using Powershell? I will basically include this powershell on my azure devops release pipeline.

Upvotes: 1

Views: 797

Answers (1)

Stephen Correia
Stephen Correia

Reputation: 81

I know this may not be the answer your looking for. As opposed to using PowerShell, where you have to handle all of the details, I would suggest that you shift your pipeline to using the Azure App Service Deploy task (https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-rm-web-app-deployment?view=azure-devops).

All you need to do is specify the slot you would like to deploy to in your parameters, whether it is new or exists.

Upvotes: 1

Related Questions