'Unable to create staging slot via YAML
I am trying to create a staging slot via yml. Here is my yml snippet:
- task: AzurePowerShell@4
displayName: 'Run Prerequisite Script'
inputs:
azureSubscription: ${{parameters.serviceConnection}}
scriptType: inlineScript
inline: |
cd\
cd ${{parameters.root}}
$fileExists = Test-Path -Path 'functions_scripts/${{ parameters.name }}/scripts/Prerequisite.ps1' -PathType Leaf
if ($fileExists) {
cd 'functions_scripts/${{ parameters.name }}/scripts'
. ./Prerequisite.ps1
Prerequisite -SolutionAbbreviation ${{parameters.solutionAbbreviation}} -EnvironmentAbbreviation ${{parameters.environmentAbbreviation}} -FunctionName ${{parameters.name}}
}
azurePowerShellVersion: LatestVersion
name: Prerequisite_${{ parameters.name }}
Here is the script:
try{
# variables
$resourceGroupName = "rg"
$functionAppname = "fa"
$slotName = 'staging'
$isFunctionAppExist = az functionapp show --name $functionAppname -g $resourceGroupName
if($null -ne $isFunctionAppExist ) {
Write-Host "Function App: $functionAppname exists."
$isDeploymentSlotExist = az functionapp deployment slot list --name $functionAppname --query "[?name=='$slotName'] | length(@)" -g $resourceGroupName
if($isDeploymentSlotExist -eq 0) {
Write-Host "Creating $slotName slot since it does not exist for function App: $functionAppname"
$success = az functionapp deployment slot create --name $functionAppname --resource-group $resourceGroupName --slot $slotName
if($null -eq $success) {
Write-Host "Slot deployment failed due to some issues, please retry again." -ForegroundColor Red
exit
}
else {
Write-Host "Slot deployment successful on Function App: $functionAppname."
}
}
else {
Write-Host "Slot: $slotName already available on Function App: $functionAppname"
}
}
}
catch
{
Write-Host "Something went wrong, please try again." -ForegroundColor Red
}
On running this, I see the following error:
##[error]ERROR: Please run 'az login' to setup account.
What am I missing? Is there a better way to create staging slot?
Solution 1:[1]
You could create a WebbApp slot in azure devops pipeline by using powershell and Microsft Hosted Agent, here is the task:
As per documentation example:
- task: AzureCLI@2
displayName: Azure CLI
inputs:
azureSubscription: <Name of the Azure Resource Manager service connection>
scriptType: ps
scriptLocation: inlineScript
inlineScript: |
az --version
az account show
and for the inline script here, used "az webapp deployment slot create" Azure CLI Command:
az webapp deployment slot create --name
--resource-group
--slot
[--configuration-source]
[--subscription]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | RajkumarMamidiChettu-MT |
