Azure Devops Pipeline task (Azure CLI#2) failing - azure

I have the below step in the Azure pipeline
- task: AzureCLI#2
displayName: get Logic App SAS Token
name: getLogicAppSASToken1
inputs:
azureSubscription: ${{ parameters.serviceAccount }}
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
$workflowDetails1 = az rest --method post --uri https://management.azure.com/subscriptions/$(SUBSCRIPTION_ID)/resourceGroups/$(RG_LOGIC_APP)/providers/Microsoft.Web/sites/$(LOGIC_APP_NAME)/hostruntime/runtime/webhooks/workflow/api/management/workflows/$(WORKFLOW_NAME1)/triggers/manual/listCallbackUrl?api-version=2018-11-01
$workflowResponse1 = $workflowDetails1 | ConvertFrom-Json
$nameValueBody1 = '{"Name":"Workflow1","value":"' + $workflowResponse1.queries.sig + '"}'
echo $nameValueBody1
$workflowDetails2 = az rest --method post --uri https://management.azure.com/subscriptions/$(SUBSCRIPTION_ID)/resourceGroups/$(RG_LOGIC_APP)/providers/Microsoft.Web/sites/$(LOGIC_APP_NAME)/hostruntime/runtime/webhooks/workflow/api/management/workflows/$(WORKFLOW_NAME2)/triggers/manual/listCallbackUrl?api-version=2018-11-01
$workflowResponse2 = $workflowDetails2 | ConvertFrom-Json
$nameValueBody2 = '{"Name":"Workflow2","value":"' + $workflowResponse2.queries.sig + '"}'
echo $nameValueBody2
Below is what I see in the logs
/usr/bin/az account set --subscription 4xxxxxxxxxxxxxxxxxxxxxxxx0313
/usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command . '/myagent/_work/_temp/azureclitaskscript1674363859719.ps1'
{"Name":"Workflow1","value":"oxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxA"}
ERROR: Bad Request({"Code":"BadRequest","Message":"Encountered an error (ServiceUnavailable) from host runtime.","Target":null,"Details":[{"Message":"Encountered an error (ServiceUnavailable) from host runtime."},{"Code":"BadRequest"},{"ErrorEntity":{"Code":"BadRequest","Message":"Encountered an error (ServiceUnavailable) from host runtime."}}],"Innererror":null})
{"Name":"Workflow2","value":""}
##[error]Script failed with exit code: 1
/usr/bin/az account clear
If you see the logs, the first API call works fine and I get the SAS Token of the Logic App Workflow. However, the second call is failing with an error as seen in the logs below. The thing that stumps me is how come the first call works and the second fails. So I assume it's not because of any configuration as if that's the case, I believe all calls should fail.
Any pointers please? Thank you!

Not sure of the exact reason why it worked. But introducing a delay of 10 seconds between the 2 API calls did the trick! Refer below.
- task: AzureCLI#2
displayName: get Logic App SAS Token
name: getLASASToken1
inputs:
azureSubscription: ${{ parameters.serviceAccount }}
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
$workflowDetails1 = az rest --method post --uri https://management.azure.com/subscriptions/$(SUBSCRIPTION_ID)/resourceGroups/$(RG_LOGIC_APP)/providers/Microsoft.Web/sites/$(LOGIC_APP_NAME)/hostruntime/runtime/webhooks/workflow/api/management/workflows/$(WORKFLOW_NAME)/triggers/manual/listCallbackUrl?api-version=2018-11-01 --debug
$workflowResponse1 = $workflowDetails1 | ConvertFrom-Json
$nameValueBody1 = '{"Name":"Workflow1-SASToken","value":"' + $workflowResponse1.queries.sig + '"}'
echo $nameValueBody1
- task: PowerShell#2
inputs:
displayName: 'Delay'
targetType: 'inline'
script: |
Start-Sleep -Seconds 10
pwsh: true
- task: AzureCLI#2
displayName: get Logic App SAS Token 2
name: getLASASToken2
inputs:
azureSubscription: ${{ parameters.serviceAccount }}
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
$workflowDetails2 = az rest --method post --uri https://management.azure.com/subscriptions/$(SUBSCRIPTION_ID)/resourceGroups/$(RG_LOGIC_APP)/providers/Microsoft.Web/sites/$(LOGIC_APP_NAME)/hostruntime/runtime/webhooks/workflow/api/management/workflows/$(WORKFLOW_NAME)/triggers/manual/listCallbackUrl?api-version=2018-11-01 --debug
$workflowResponse2 = $workflowDetails2 | ConvertFrom-Json
$nameValueBody2 = '{"Name":"Workflow2-SASToken","value":"' + $workflowResponse2.queries.sig + '"}'
echo $nameValueBody2

Related

Set variable on azure task to pass another task of Azure pipeline

I am able to set a variable on powershell or bash script and pass the variable to another task by using ##vso[task.setvariable variable=abc;]xyz. But couldn't find any documentation to set variable on azure tasks like azure webapp deploy task or SqlAzureDacpacDeployment task. I want to catch the error by passing the variable value. Is there any effective way to catch the azure task error log for the next task?
- task: SqlAzureDacpacDeployment#1
displayName: 'Insertion SQL Task'
inputs:
azureSubscription: 'Org (xxxxx-xxxx-xxxx-xxxx-xxxx)'
ServerName: 'tcp:abc.database.windows.net'
DatabaseName: test_db
SqlUsername: '$(user)'
SqlPassword: $(pass)
deployType: SqlTask
SqlFile: 'SQL/test.sql'
enabled: true
- task: AzureWebApp#1
displayName: 'Azure Web App Deploy: $(AppName)'
inputs:
azureSubscription: 'Org (xxxxx-xxxx-xxxx-xxxx-xxxx)'
appType: webApp
ResourceGroupName: 'Test'
appName: '$(AppName)'
package: '$(Build.ArtifactStagingDirectory)\app/*.zip'
deploymentMethod: zipDeploy
enabled: true
You will need to set a name for the task.
For Azure SQL Database Deployment task, you can use the SqlDeploymentOutputFile output variable name.
- task: SqlAzureDacpacDeployment#1
displayName: 'Insertion SQL Task'
name: sqlInsert
inputs:
...
enabled: true
- script: echo "$(sqlInsert.SqlDeploymentOutputFile)"
The Azure Web App task does not provide the same mechanism. You could always call the Pipelines - Get Logs API to get what you need:
pool:
vmImage: ubuntu-latest
steps:
- powershell: Write-Host "Hello World"
name: 'HelloWorld'
- powershell: |
Write-Host "This is a script that could use $env:SYSTEM_ACCESSTOKEN"
# Construct the REST URL to obtain Build ID
$uri = "$(System.CollectionUri)$(System.TeamProject)/_apis/pipelines/$(System.DefinitionId)/runs/$(Build.BuildId)/logs?api-version=6.0-preview.1"
Write-Host "$uri"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "system", $env:SYSTEM_ACCESSTOKEN)))
$logs = Invoke-RestMethod -Uri $uri -Method Get -ContentType "application/json" -Headers #{Authorization=("Basic {0}" -f $base64AuthInfo)}
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)

Azure Devops : Set a variable for future stages and Job not working

I am trying to generate a random string of length 32 characters in Build Stage, then I want to pass the same to the next job/deployment And Also to the next Stage.
I referred to https://learn.microsoft.com/en-us/azure/devops/pipelines/process/set-variables-scripts?view=azure-devops&tabs=powershell to pass a variable from one job to another job and stage. But it is not working, Here is my pipeline code YAML file.
trigger: none
pool:
name: agentpool-myproj
stages:
- stage: 'BuildStage'
variables:
- group: myproj-vargrp-common-dp-poc
displayName: 'BuildStage'
jobs:
- deployment: BuildStageSecretProducerjobs # deployment is equal to job
environment: dev
displayName: 'BuildStageSecretProducerjobs'
strategy:
runOnce:
deploy:
steps:
- checkout: none
- download: none
- task: AzurePowerShell#5
name: mastertask
inputs:
azureSubscription: 'con-myproj-dev'
ScriptType: 'InlineScript'
Inline: |
$Random32Key = -join (((48..57)+(65..90)+(97..122)) |Get-Random -Count 32 |%{[char]$_})
Write-Host "##vso[task.setvariable variable=supersecret;isoutput=true;issecret=false]$Random32Key"
FailOnStandardError: true
azurePowerShellVersion: LatestVersion
- deployment: BuildStageSecretConsumerjobs
dependsOn: BuildStageSecretProducerjobs
variables:
thissupersecret: $[ dependencies.BuildStageSecretProducerjobs.outputs['masterjob.supersecret'] ]
environment: dev
displayName: 'BuildStageSecretConsumer'
strategy:
runOnce:
deploy:
steps:
- checkout: none
- download: none
- task: PowerShell#2
inputs:
targetType: 'inline'
script: |
# Write your PowerShell commands here.
Write-Host $(thissupersecret)
- stage: 'DeployStage'
dependsOn: 'BuildStage'
condition: succeeded('BuildStage')
displayName: 'DeployStage'
jobs:
- deployment: DeployStageSecretconsumerjobs # deployment is equal to job
variables:
thissupersecret: $[stageDependencies.BuildStage.BuildStageSecretProducerjobs.outputs['mastertask.supersecret']]
environment: dev
displayName: 'DeployStageSecretconsumerjobs'
strategy:
runOnce:
deploy:
steps:
- checkout: none
- download: none
- task: PowerShell#2
inputs:
targetType: 'inline'
script: |
# Write your PowerShell commands here.
Write-Host $(thissupersecret)
$releaseurl = ('{0}{1}/_apis/release/releases/{2}?api-version=5.0' -f $($env:SYSTEM_TEAMFOUNDATIONSERVERURI), $($env:SYSTEM_TEAMPROJECTID), $($env:RELEASE_RELEASEID) )
$Release = Invoke-RestMethod -Uri $releaseurl -Headers #{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}
$variableName = '<HERE_VARIABLE_NAME>'
$release.variables.($variableName).value = "<YOUR VALUE HERE IN STRING OR REFERNCE TO A VARIABLE E.G. $(OTHER_VARIABLE)>"
$json = #($release) | ConvertTo-Json -Depth 99
Invoke-RestMethod -Uri $releaseurl -Method Put -Body $json -ContentType "application/json" -Headers #{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" }
$Release = Invoke-RestMethod -Uri $releaseurl -Headers #{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}
Above is 100% working for Releases in ADO. Try to dig for URLs referencing Builds and you should be fine. Of course is you opt to Powershell.

Microsoft Dev Ops yaml variables between deployments

So at it's core what I'm essentially trying to do is this:
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/deployment-jobs?view=azure-devops&preserve-view=true#support-for-output-variables
Which breaks down to the fact that I have a single deployment template that produces an output variable that I want to map back to a variable in my main template so that I can use it in subsequent deployment templates.
I have created a github project with all of my yaml templates here
https://github.com/MCKRUZ/azure-pipelines
but the crux of the problem lies in these few lines. First I'm calling a template deployment in my main "development.yaml" file.
# Deploy
# ------
- stage: Deploy
displayName: Deploy - Development
jobs:
- template: jobs/jobs-deploy-spa-arm-template.yaml
parameters:
environment: '$(environment)'
serviceConnection: '$(serviceConnection)'
subscriptionId: '$(subscriptionId)'
resourceGroup: '$(resourceGroup)'
storageAccountName: '$(storageAccountName)'
cdnEndpointName: '$(cdnEndpointName)'
cdnProfileName: '$(cdnProfileName)'
deploymentLocation: '$(deploymentLocation)'
armTemplateArtifactName: ${{ variables['armTemplateArtifactName'] }}
storageAccountCSMFilePath: '$(storageAccountCSMFilePath)'
storageAccountCSMParametersFile: '$(storageAccountCSMParametersFile)'
deployCDN: '${{ variables.isProduction }}'
cdnCSMFilePath: '$(cdnCSMFilePath)'
cdnCSMParametersFile: '$(cdnCSMParametersFile)'
That template looks like this:
# Parameters
# ---------
parameters:
- name: environment
type: string
- name: serviceConnection
type: string
- name: subscriptionId
type: string
- name: resourceGroup
type: string
- name: storageAccountName
type: string
- name: cdnEndpointName
type: string
- name: cdnProfileName
type: string
- name: deploymentLocation
type: string
- name: armTemplateArtifactName
type: string
- name: storageAccountCSMFilePath
type: string
- name: storageAccountCSMParametersFile
type: string
- name: deployCDN
type: boolean
default: false
- name: cdnCSMFilePath
type: string
- name: cdnCSMParametersFile
type: string
- name: overrideParameterFile
type: boolean
default: true
# Jobs
# ---------
jobs:
# Job - Deploy SPA ARM Template
# ---------
- #deployment: '${{ parameters.armTemplateArtifactName }}'
deployment: armTemplates
variables:
storageAccountNameCalculated: ''
cdnEndpointNameCalculated: ''
displayName: Deploy SPA ARM Template
environment: ${{ parameters.environment }}
workspace:
clean: all
strategy:
runOnce:
deploy:
steps:
# Bash - Show Input Parameter Variables
# ---------
- bash: |
echo ''
echo '===== Deploy SPA ARM Template Input Variables ====='
echo ''
echo ' ===== Parameters ====='
echo ' environment: ${{ parameters.environment }}'
echo ' serviceConnection: ${{ parameters.serviceConnection }}'
echo ' subscriptionId: ${{ parameters.subscriptionId }}'
echo ' resourceGroup: ${{ parameters.resourceGroup }}'
echo ' storageAccountName: ${{ parameters.storageAccountName }}'
echo ' cdnEndpointName: ${{ parameters.cdnEndpointName }}'
echo ' cdnProfileName: ${{ parameters.cdnProfileName }}'
echo ' deploymentLocation: ${{ parameters.deploymentLocation }}'
echo ' armTemplateArtifactName: ${{ parameters.armTemplateArtifactName }}'
echo ' storageAccountCSMFilePath: ${{ parameters.storageAccountCSMFilePath }}'
echo ' storageAccountCSMParametersFile: ${{ parameters.storageAccountCSMParametersFile }}'
echo ' deployCDN: ${{ parameters.deployCDN }}'
echo ' cdnCSMFilePath: ${{ parameters.cdnCSMFilePath }}'
echo ' cdnCSMParametersFile: ${{ parameters.cdnCSMParametersFile }}'
echo ''
displayName: Debug - Input Parameters
# Task - Deploy Storage Account ARM Template
# ---------
- task: AzureResourceManagerTemplateDeployment#3
displayName: Deploy Storage Account ARM Template
inputs:
deploymentScope: 'Resource Group'
azureResourceManagerConnection: '${{ parameters.serviceConnection }}'
subscriptionId: '${{ parameters.subscriptionId }}'
action: 'Create Or Update Resource Group'
resourceGroupName: '${{ parameters.resourceGroup }}'
location: '${{ parameters.deploymentLocation }}'
templateLocation: 'Linked artifact'
csmFile: '$(Pipeline.Workspace)\${{ parameters.armTemplateArtifactName }}\${{ parameters.storageAccountCSMFilePath }}'
csmParametersFile: '$(Pipeline.Workspace)\${{ parameters.armTemplateArtifactName }}\${{ parameters.storageAccountCSMParametersFile }}'
deploymentMode: 'Incremental'
deploymentName: 'storageAccountDeployment'
deploymentOutputs: 'storageAccountDeploymentOutput'
${{ if eq(parameters.overrideParameterFile, 'true') }}:
overrideParameters: '-formatNames true -environment ${{ parameters.environment }} -storageAccountName ${{ parameters.storageAccountName }}'
# Task - Retrieve Output Variable
#----------
- task: AzurePowerShell#5
displayName: Retrieve Output Variables
name: retrieveStorageAccountDeploymentOutput
condition: succeeded()
inputs:
azureSubscription: '${{ parameters.serviceConnection }}'
scriptType: 'inlineScript'
azurePowerShellVersion: 'LatestVersion'
inline: |
$armOutput = '$(storageAccountDeploymentOutput)' | ConvertFrom-Json
Write-Output "##vso[task.setvariable variable=storageAccountNameCalculated;]$($armOutput.storageAccountName.value)"
- script: echo "##vso[task.setvariable variable=myOutputVar;isOutput=true]this is the deployment variable value"
name: setvarStep
- script: echo $(setvarStep.myOutputVar)
name: echovar
# Task - Add Static Hosting to Storage Account
# ---------
- task: AzurePowerShell#5
displayName: Add Static Hosting to Storage Account
condition: succeeded()
inputs:
azureSubscription: '${{ parameters.serviceConnection }}'
scriptType: 'inlineScript'
azurePowerShellVersion: latestVersion
inline: |
$StorageAccount = Get-AzStorageAccount -Name $(storageAccountNameCalculated) -ResourceGroupName '${{ parameters.resourceGroup }}'
Enable-AzStorageStaticWebsite -Context $StorageAccount.Context -IndexDocument index.html -ErrorDocument404Path index.html
# Task - Deploy CDN ARM Template
# ---------
- task: AzureResourceManagerTemplateDeployment#3
displayName: Deploy CDN ARM Template
condition: and(succeeded(), eq(${{ parameters.deployCDN }}, 'true'))
inputs:
deploymentScope: 'Resource Group'
azureResourceManagerConnection: '${{ parameters.serviceConnection }}'
subscriptionId: '${{ parameters.subscriptionId }}'
action: 'Create Or Update Resource Group'
resourceGroupName: '${{ parameters.resourceGroup }}'
location: '${{ parameters.deploymentLocation }}'
templateLocation: 'Linked artifact'
csmFile: '$(Pipeline.Workspace)\${{ parameters.armTemplateArtifactName }}\${{ parameters.cdnCSMFilePath }}'
csmParametersFile: '$(Pipeline.Workspace)\${{ parameters.armTemplateArtifactName }}\${{ parameters.cdnCSMParametersFile }}'
deploymentMode: 'Incremental'
deploymentName: 'cdnDeployment'
deploymentOutputs: 'CDNDeployOutput'
${{ if eq(parameters.overrideParameterFile, 'true') }}:
overrideParameters: '-formatNames true -environment ${{ parameters.environment }} -cdnEndpointName ${{ parameters.cdnEndpointName }} -cdnProfileName ${{ parameters.cdnProfileName }} -storageAccountPrimaryEndpoint -storageAccountPrimaryEndpoint $storageAccountNameCalculated.z13.web.core.windows.net'
# Task - Retrieve Output Variable
#----------
- task: AzurePowerShell#5
displayName: Retrieve Output Variables
condition: and(succeeded(), eq(${{ parameters.deployCDN }}, 'true'))
inputs:
azureSubscription: '${{ parameters.serviceConnection }}'
scriptType: 'inlineScript'
azurePowerShellVersion: 'LatestVersion'
inline: |
$armOutput = '$(CDNDeployOutput)' | ConvertFrom-Json
Write-Output "##vso[task.setvariable variable=cdnEndpointNameCalculated;isOutput=true]$($armOutput.cdnEndpointName)"
# Bash - Show Output Parameter Variables
# ---------
- bash: |
echo ''
echo '===== Deploy SPA ARM Template Output Variables ====='
echo ''
echo ' ===== Parameters ====='
echo ' storageAccountNameCalculated: $(storageAccountNameCalculated)'
echo ' cdnEndpointName: $(cdnEndpointNameCalculated)'
echo ''
displayName: Debug - Output Parameters
Where I'm using these two lines
- script: echo "##vso[task.setvariable variable=myOutputVar;isOutput=true]this is the deployment variable value"
name: setvarStep
- script: echo $(setvarStep.myOutputVar)
name: echovar
To try and isolate a way that I can create a variable that will be able to be used back in my main yaml file. When I look at the logs, the second echo successfully echos out the variable so I know that part works at least. Once this runs, back in my main yaml file I call this.
- job: job_deploy_code
displayName: Deploy Some Code
dependsOn: armTemplates
variables:
myVarFromDeploymentJob: $[ dependencies.armTemplates.outputs['deploy_Development.setvarStep.myOutputVar'] ]
steps:
- script: "echo $(myVarFromDeploymentJob)"
name: echovar
Which is just supposed to echo back what is in my variable. Right now it's blank. I know it's some stupid syntax that I'm not seeing but I can't for the life of me figure out what it is.
I solved this with the correct syntax
- job: job_deploy_code
displayName: Deploy Some Code
dependsOn: armTemplates
variables:
myVarFromDeploymentJob: $[ dependencies.armTemplates.outputs['armTemplates.setvarStep.myOutputVar'] ]

IF statement condition within a Azure devops pipeline

EDIT
I have got a pipeline below and would want it to run an inline script based on the time of the day.
The question should have been around pipelines rather than ARM template.
schedules:
- cron: "0 10 * * *"
displayName: Test 1
branches:
include:
- master
always: true
- cron: "0 21 * * *"
displayName: Test 2
branches:
include:
- master
always: true
steps:
- ${{ if eq(schedules.cron, '0 10 ***') }}:
- task: AzureCLI#2
name: RunProcess
displayName: Run test 1
inputs:
azureSubscription: serviceConnection
scriptLocation: 'inlineScript'
scriptType: bash
failOnStandardError: true
inlineScript: |
echo 'starting process 1'
The way I was able to do this can be found below.
steps:
- task: PowerShell#02
name: taskname
displayName: task display name
inputs:
azureSubscription: $(subnamee)
scriptLocation: 'inlineScript'
failOnStandardError: true
targetType: 'inline'
script: |
$h = (Get-Date).hour
if ($h -eq 10)
{
echo 'command 1'
}
if ($h -eq 21)
{
echo 'command 2'
}
I was able to do this by changing the script type to PS.
The way I was able to do this can be found below.
steps:
- task: PowerShell#02
name: taskname
displayName: task display name
inputs:
azureSubscription: $(subnamee)
scriptLocation: 'inlineScript'
failOnStandardError: true
targetType: 'inline'
script: |
$h = (Get-Date).hour
if ($h -eq 10)
{
echo 'command 1'
}
if ($h -eq 21)
{
echo 'command 2'
}

Azure DevOps YAML template passing hashset/map/dictionary/object - key value?

Say I have a main azure devops pipeline azure-pipelines.yml in which I call into my template deploy.yml.
In the main pipeline I'd like to be able to declare either a variable or a parameter of type hashset / map / dictionary or any other key value structure that I can then pass to the template.
I can see that it's possible to pass in an object type, but I can't wrap my head it's usage. How could I achieve the following?
Note the appSettings: {"key1":"value1","key2":"value2"} in azure-pipelines.yml is a fantasy, but showcases pretty well how I'd like this to work.
azure-pipelines.yml:
trigger:
- main
- job: deploy
pool:
vmImage: ${{ parameters.poolVmImage }}
steps:
- template: deploy.yml
parameters:
azureServiceConnection: ${{ parameters.azureServiceConnection }}
resourceGroupName: 'foo'
appServiceName: 'bar'
appSettings: {"key1":"value1","key2":"value2"}
deploy.yml:
parameters:
- name: azureServiceConnection
- name: resourceGroupName
- name: appServiceName
- name: appSettings
steps:
- task: AzureCLI#2
displayName: Deploy zip
name: deployZip
inputs:
azureSubscription: ${{ parameters.azureServiceConnection }}
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
az webapp deployment source config-zip \
-g ${{ parameters.resourceGroupName }} \
-n ${{ parameters.appServiceName }} \
--src ./deployment.zip
az webapp config appsettings set \
-g ${{ parameters.resourceGroupName }} \
-n ${{ parameters.appServiceName }} \
--settings ${{ parameters.appSettings }}
How could I achieve the following?
You can indeed use object type parameters.
But in the template, you cannot use multiple object parameters at once, so you need to use each expression to loop through each object.
For example: - ${{ each setting in parameters.appSettings }}:
Here is my sample, you could refer to:
Deploy.yml:
parameters:
- name: azureServiceConnection
- name: resourceGroupName
- name: appServiceName
- name: appSettings
type: object
default: []
steps:
- task: AzureCLI#2
displayName: Deploy zip
name: deployZip
inputs:
azureSubscription: ${{ parameters.azureServiceConnection }}
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
az webapp deployment source config-zip \
-g ${{ parameters.resourceGroupName }} \
-n ${{ parameters.appServiceName }} \
--src ./deployment.zip
- ${{ each setting in parameters.appSettings }}:
- task: AzureCLI#2
displayName: Deploy settings
inputs:
azureSubscription: ${{ parameters.azureServiceConnection }}
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
az webapp config appsettings set \
-g ${{ parameters.resourceGroupName }} \
-n ${{ parameters.appServiceName }} \
--settings ${{ setting }}
azure-pipelines.yml:
trigger:
- none
parameters:
- name: InstanceArgs
type: object
default: [key2=value2,key3=value3]
jobs:
- job: deploy
pool:
vmImage: windows-latest
steps:
- template: deploy.yml
parameters:
azureServiceConnection: '${{ parameters.azureServiceConnection }}'
resourceGroupName: 'foo'
appServiceName: 'bar'
appSettings: ${{ parameters.InstanceArgs }}
Note: Since the parameters in the template are obejct type , the same type of parameters need to be set in the main yaml file to pass the object.
Workflow: Pass the object type parameters to the template. The template will run the deploy zip command first. Then it will traverse each object passed, and use the config settings command to pass them to the webapp one by one.
Result:

Resources