microsoft / azure-pipelines-tasks

Tasks for Azure Pipelines
https://aka.ms/tfbuild
MIT License
3.5k stars 2.61k forks source link

AzureResourceManagerTemplateDeployment@3 or AzureResourceGroupDeployment@2 outputs not working when a value is null #14246

Closed cloudlucky closed 3 years ago

cloudlucky commented 3 years ago

Type: Bug

Enter Task Name: AzureResourceManagerTemplateDeployment@3 and AzureResourceGroupDeployment@2 outputs fail to create variable when the property value is null.

list here (V# not needed):

Environment

Issue Description

Setup:

When a property value of the ARM Template output is "null" then it fails to create the deploymentOutputs variable.

For example (some lines have been removed for clarity): In the yml build definition

        - task: AzureResourceManagerTemplateDeployment@3
          inputs:
            [.....]
            csmFile: '$(dropDirectory)/armTemplates/FunctionsAppServicePlan-Template.json'
            csmParametersFile: '$(dropDirectory)/armTemplates/FunctionsAppServicePlan-Parameters.json'
            overrideParameters: -environment $(EnvironmentNameLower) -name Platform
            deploymentOutputs: 'functionsAppServicePlanOutputs'

In the log window:

2021-01-18T13:46:47.5848445Z Updated output variable 'appInsightsOutputs.appInsightsObject.value.provisioningState', which contains the outputs section of the current deployment object in string format.
2021-01-18T13:46:47.5873832Z (node:6392) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot convert undefined or null to object

Then for the next task, the variable "functionsAppServicePlanOutputs" is not defined.

Also, when this happens, the task finish sucessfully but the output variable is not created.

Task logs

ARM Templates and Logs.zip I included two ARM Templates where I can reproduce the issue:

Error logs

2021-01-18T13:46:47.5842828Z Updated output variable 'appInsightsOutputs.appInsightsObject.value.CreationDate', which contains the outputs section of the current deployment object in string format.
2021-01-18T13:46:47.5845800Z Updated output variable 'appInsightsOutputs.appInsightsObject.value.TenantId', which contains the outputs section of the current deployment object in string format.
2021-01-18T13:46:47.5848445Z Updated output variable 'appInsightsOutputs.appInsightsObject.value.provisioningState', which contains the outputs section of the current deployment object in string format.
2021-01-18T13:46:47.5873832Z (node:6392) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot convert undefined or null to object
Viper61x23 commented 3 years ago

I am also having exactly the same issue, here is part of my ARM template with the output.

"outputs": { "endpoints": { "type": "array", "value": [ "[if(equals(parameters('tfm-exists-account-assets'), 1), reference(resourceId('Microsoft.Network/trafficManagerProfiles', variables('tfmp-account-assets')), '2018-08-01', 'Full').properties.endpoints, json('[]'))]", "[if(equals(parameters('tfm-exists-identity-migration-api'), 1), reference(resourceId('Microsoft.Network/trafficManagerProfiles', variables('tfmp-identity-migration-api')), '2018-08-01', 'Full').properties.endpoints, json('[]'))]", "[if(equals(parameters('tfm-exists-identity-api'), 1), reference(resourceId('Microsoft.Network/trafficManagerProfiles', variables('tfmp-identity-api')), '2018-08-01', 'Full').properties.endpoints, json('[]'))]", "[if(equals(parameters('tfm-exists-identity-audit-api'), 1), reference(resourceId('Microsoft.Network/trafficManagerProfiles', variables('tfmp-identity-audit-api')), '2018-08-01', 'Full').properties.endpoints, json('[]'))]", "[if(equals(parameters('tfm-exists-customerservice'), 1), reference(resourceId('Microsoft.Network/trafficManagerProfiles', variables('tfmp-customerservice')), '2018-08-01', 'Full').properties.endpoints, json('[]'))]" ] }

Here is the log:

2021-01-19T22:41:01.4251010Z Updated output variable 'endpoints.endpoints.type', which contains the outputs section of the current deployment object in string format. 2021-01-19T22:41:01.4253061Z Updated output variable 'endpoints.endpoints.value.0.0.id', which contains the outputs section of the current deployment object in string format. 2021-01-19T22:41:01.4254846Z Updated output variable 'endpoints.endpoints.value.0.0.name', which contains the outputs section of the current deployment object in string format. 2021-01-19T22:41:01.4255685Z Updated output variable 'endpoints.endpoints.value.0.0.type', which contains the outputs section of the current deployment object in string format. 2021-01-19T22:41:01.4257134Z Updated output variable 'endpoints.endpoints.value.0.0.properties.endpointStatus', which contains the outputs section of the current deployment object in string format. 2021-01-19T22:41:01.4265383Z Updated output variable 'endpoints.endpoints.value.0.0.properties.endpointMonitorStatus', which contains the outputs section of the current deployment object in string format. 2021-01-19T22:41:01.4266119Z Updated output variable 'endpoints.endpoints.value.0.0.properties.targetResourceId', which contains the outputs section of the current deployment object in string format. 2021-01-19T22:41:01.4266996Z Updated output variable 'endpoints.endpoints.value.0.0.properties.target', which contains the outputs section of the current deployment object in string format. 2021-01-19T22:41:01.4269524Z Updated output variable 'endpoints.endpoints.value.0.0.properties.weight', which contains the outputs section of the current deployment object in string format. 2021-01-19T22:41:01.4270784Z Updated output variable 'endpoints.endpoints.value.0.0.properties.priority', which contains the outputs section of the current deployment object in string format. 2021-01-19T22:41:01.4271595Z Updated output variable 'endpoints.endpoints.value.0.0.properties.endpointLocation', which contains the outputs section of the current deployment object in string format. 2021-01-19T22:41:01.4297021Z (node:19224) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot convert undefined or null to object

We are trying to extract the endpoint information into the output variable, from the logs you can see that only part of the first endpoint associated with the first traffic manager is processed, then it fails.

It is also worth noting that this used to work with Deployment version 2.175.2 but has stopped working now on 2.179.0

I can provide the pipeline details like above if required.

Viper61x23 commented 3 years ago

My original error was not showing any stack trace due to converting to JSON. However I modified my arm template just to change the output and I now get a stacktrace:

2021-01-31T21:44:20.2637860Z (node:4588) UnhandledPromiseRejectionWarning: TypeError: Cannot convert undefined or null to object 2021-01-31T21:44:20.2641096Z at Function.keys (<anonymous>) 2021-01-31T21:44:20.2641393Z at setVariablesInObject (F:\AgentA\_work\_tasks\AzureResourceGroupDeployment_94a74903-f93f-4075-884f-dc11f34058b4\2.180.0\operations\ResourceGroup.js:525:56) 2021-01-31T21:44:20.2641530Z at setVariablesInObject (F:\AgentA\_work\_tasks\AzureResourceGroupDeployment_94a74903-f93f-4075-884f-dc11f34058b4\2.180.0\operations\ResourceGroup.js:527:41) 2021-01-31T21:44:20.2641647Z at setVariablesInObject (F:\AgentA\_work\_tasks\AzureResourceGroupDeployment_94a74903-f93f-4075-884f-dc11f34058b4\2.180.0\operations\ResourceGroup.js:527:41) 2021-01-31T21:44:20.2641875Z at setVariablesInObject (F:\AgentA\_work\_tasks\AzureResourceGroupDeployment_94a74903-f93f-4075-884f-dc11f34058b4\2.180.0\operations\ResourceGroup.js:527:41) 2021-01-31T21:44:20.2641993Z at setVariablesInObject (F:\AgentA\_work\_tasks\AzureResourceGroupDeployment_94a74903-f93f-4075-884f-dc11f34058b4\2.180.0\operations\ResourceGroup.js:527:41) 2021-01-31T21:44:20.2642151Z at setVariablesInObject (F:\AgentA\_work\_tasks\AzureResourceGroupDeployment_94a74903-f93f-4075-884f-dc11f34058b4\2.180.0\operations\ResourceGroup.js:527:41) 2021-01-31T21:44:20.2642265Z at setVariablesInObject (F:\AgentA\_work\_tasks\AzureResourceGroupDeployment_94a74903-f93f-4075-884f-dc11f34058b4\2.180.0\operations\ResourceGroup.js:527:41) 2021-01-31T21:44:20.2642401Z at armClient.deployments.createOrUpdate (F:\AgentA\_work\_tasks\AzureResourceGroupDeployment_94a74903-f93f-4075-884f-dc11f34058b4\2.180.0\operations\ResourceGroup.js:536:33) 2021-01-31T21:44:20.2642549Z at client.beginRequest.then.then (F:\AgentA\_work\_tasks\AzureResourceGroupDeployment_94a74903-f93f-4075-884f-dc11f34058b4\2.180.0\node_modules\azure-pipelines-tasks-azure-arm-rest-v2\DeploymentsBase.js:82:32) 2021-01-31T21:44:20.2642707Z (node:4588) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) 2021-01-31T21:44:20.2642872Z (node:4588) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Seems to be related to Node.js.

pradudev commented 3 years ago

I have created a PR for the fix: GitHub link

pradudev commented 3 years ago

@bishal-pdMSFT Hi, when can I expect the new version(v2.182.0 and v3.182.0) of the two ARM deployment tasks with the fixes in it?

ddivanshu commented 3 years ago

@pradudev Its been deployed.

cloudlucky commented 3 years ago

I can confirm that my deployment scripts are working now with this fix. Thank you everyone

bishal-pdMSFT commented 3 years ago

Special shout out to @pradudev for creating PR for fixing this issue ❤️