New-AzResourceGroupDeployment fails if you add parameter -asjob #6644
-
|
When I am deploying a long running resource like Site to site VPN I would like to run it in background so I can continue with other deployments. Adding this parameter does not work for me, if I ran
value in bicep file is not hardcoded as it is red from *.json template file then name is constructed from this parameter in bicep file
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 12 replies
-
|
I am not able to repro you scenario, can you please confirm you have the latest AZ PowerShell Modules, then also follow the steps below and let me know how you go.
get-module
ModuleType Version PreRelease Name
Script 2.7.5 Az.Accounts
Script 5.4.0 Az.ResourcesHere is a repro
param envname string
param location string
param now string = utcNow()
resource deploymentScript 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
name: 'testparamsasjob'
location: location
kind: 'AzurePowerShell'
properties: {
azPowerShellVersion: '6.6'
arguments: ' -envname ${envname}'
scriptContent: '''
param (
[string]$envname
)
echo $envname
$DeploymentScriptOutputs = @{}
$DeploymentScriptOutputs['envName'] = $envname
'''
forceUpdateTag: now
cleanupPreference: 'OnSuccess'
retentionInterval: 'P1D'
timeout: 'PT3M'
}
}
output deploymentScriptOutput object = deploymentScript.properties.outputs.envNameexecuted without -asjob
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"envname": {
"value": "helloworld"
},
"location": {
"value": "centralus"
}
}
}New-AzResourceGroupDeployment -verbose -ResourceGroupName xyz -TemplateFile D:\asjob.bicep -TemplateParameterFile D:\asjob-params.jsonNow test with -asjob and using a param file New-AzResourceGroupDeployment -asJob -verbose -ResourceGroupName xyz -TemplateFile D:\asjob.bicep -TemplateParameterFile D:\asjob-params.json
get-job | ft -AutoSize
Id Name PSJobTypeName State HasMoreData Location Command
-- ---- ------------- ----- ----------- -------- -------
1 Long Running Operation for 'New-AzResourceGroupDeployment' AzureLongRunningJob`1 Running True localhost New-AzResourceGroupDeployment
get-job | ft -AutoSize
Id Name PSJobTypeName State HasMoreData Location Command
-- ---- ------------- ----- ----------- -------- -------
1 Long Running Operation for 'New-AzResourceGroupDeployment' AzureLongRunningJob`1 Completed True localhost New-AzResourceGroupDeployment
get-job | Receive-Job -Keep | ft -AutoSize
ResourceGroupName OnErrorDeployment DeploymentName CorrelationId ProvisioningState Timestamp Mode TemplateLink TemplateLinkString DeploymentDebugLogLevel
----------------- ----------------- -------------- ------------- ----------------- --------- ---- ------------ ------------------ -----------------------
ACU1-BRW-AOA-RG-T5 asjob e831baa6-407a-4e26-86c0-a03e1b91286c Succeeded 4/30/2022 6:03:14 PM Incremental
$output = get-job | Receive-Job -Keep
$output
DeploymentName : asjob
ResourceGroupName : ACU1-BRW-AOA-RG-T5
ProvisioningState : Succeeded
Timestamp : 4/30/2022 6:03:14 PM
Mode : Incremental
TemplateLink :
Parameters :
Name Type Value
=============== ========================= ==========
envname String "helloworld"
location String "centralus"
now String "20220430T180120Z"
Outputs :
Name Type Value
======================== ========================= ==========
deploymentScriptOutput String "helloworld" |
Beta Was this translation helpful? Give feedback.
-
|
Hi thanks for all suggestions we had a national holiday here so I was away, will test your recommendations and will report back! |
Beta Was this translation helpful? Give feedback.
-
|
Hi @brwilkinson , I tested your recommendation and it solved my issue. I used fully qualified path to both template and parameter file and adding |
Beta Was this translation helpful? Give feedback.
-
|
Hi @BethanyZhou I have another one here to take a look into.
The working directory is not being set in the background job, so the Full repro is above for the working scenario. For normal jobs the |
Beta Was this translation helpful? Give feedback.
-
|
@brwilkinson I am deploying this from location where my modules are located like This one fails, but works normally without -asjob: This is error: This one works fine: |
Beta Was this translation helpful? Give feedback.







I am not able to repro you scenario, can you please confirm you have the latest AZ PowerShell Modules, then also follow the steps below and let me know how you go.
Ctrl + Cso long as the you seeVERBOSE: 11:07:55 AM - Template is valid.then you can stop the deployment and it will continue to run in Azure.Here is a repro
Bicepscript to test this scenario.asjob.bicep