microsoft / azure-pipelines-tasks

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

[BUG]: AzureFunctionAppV2 unable to set connectedServiceNameARM at run time. Fails with error, Input required: azureSubscription #20350

Open erenken opened 2 weeks ago

erenken commented 2 weeks ago

New issue checklist

Task name

AzureFunctionAppV2

Task version

2.244.3

Issue Description

I am trying to build a pipeline that I can use for both QA and Production. I have it pulling variables from variable groups:

        - ${{ if ne(variables['Build.SourceBranch'], 'refs/heads/main') }}:
          - group: qaGroup
        - ${{ if or(eq(variables['Build.SourceBranch'], 'refs/heads/main'), eq(variables['Build.SourceBranch'], 'refs/heads/work/prodPipeline')) }}:
          - group: prodGroup
        - name: azureConnector
          value: $[variables.AzureServiceConnection]

Then my task looks like this:

        - task: AzureFunctionApp@2
          inputs:
            connectedServiceNameARM: '$(azureConnector)'
            appType: 'functionApp'
            appName: 'func-xxx-$(environmentName)-notifications'
            package: '$(Pipeline.Workspace)/xxx.Notifications.zip'
            appSettings: '-Version "$(branchTag)"' 
            deploymentMethod: 'runFromPackage'

When it runs, I get the error, Input required: azureSubscription.

In the log I can see the variable being set correctly:

  azureConnector:
    Parsing expression: <variables.AzureServiceConnection>
    Evaluating: variables['AzureServiceConnection']
    Result: 'azure-prod-subscription'

When I also look at the task settings in the Azure DevOps there isn't an input called 'azureSubscription`.

If I try adding azureSubscription to the inputs I get this warning from the DevOps editor, Multiple properties found matching connectedServiceNameARM

Environment type (Please select at least one enviroment where you face this issue)

Azure DevOps Server type

dev.azure.com (formerly visualstudio.com)

Azure DevOps Server Version (if applicable)

Agent Version: 3.243.0, Hosted Agent

Operation system

Microsoft Windows 10.0.20348

Relevant log output

##[debug]loading INPUT_APPNAME
##[debug]loading INPUT_APPSETTINGS
##[debug]loading INPUT_APPTYPE
##[debug]loading INPUT_DEPLOYMENTMETHOD
##[debug]loading INPUT_DEPLOYTOSLOTORASE
##[debug]loading INPUT_ISFLEXCONSUMPTION
##[debug]loading INPUT_PACKAGE
##[debug]loading INPUT_SLOTNAME
##[debug]loading SECRET_IDENTITYAPIUSERPASSWORD
##[debug]loading SECRET_SENDGRIDAPIKEY
##[debug]loading SECRET_SYSTEM_ACCESSTOKEN
##[debug]loaded 14
##[debug]Agent.ProxyUrl=undefined
##[debug]Agent.CAInfo=undefined
##[debug]Agent.ClientCert=undefined
##[debug]Agent.SkipCertValidation=undefined
##[debug]agent.proxyurl=undefined
##[debug]VSTS_ARM_REST_IGNORE_SSL_ERRORS=undefined
##[debug]AZURE_HTTP_USER_AGENT=VSTS_0a260fa7-f57f-45d9-ac9b-c8145c5a6af8_build_37_0
##[debug]Using msalv2
##[debug]check path : D:\a\_tasks\AzureFunctionApp_501dd25d-1785-43e4-b4e5-a5c78ccc0573\2.244.3\node_modules\azure-pipelines-tasks-azure-arm-rest\module.json
##[debug]adding resource file: D:\a\_tasks\AzureFunctionApp_501dd25d-1785-43e4-b4e5-a5c78ccc0573\2.244.3\node_modules\azure-pipelines-tasks-azure-arm-rest\module.json
##[debug]system.culture=en-US
##[debug]Agent.TempDirectory=D:\a\_temp
##[debug]Resource file has already set to: D:\a\_tasks\AzureFunctionApp_501dd25d-1785-43e4-b4e5-a5c78ccc0573\2.244.3\node_modules\azure-pipelines-tasks-azure-arm-rest\module.json
##[debug]Resource file has already set to: D:\a\_tasks\AzureFunctionApp_501dd25d-1785-43e4-b4e5-a5c78ccc0573\2.244.3\node_modules\azure-pipelines-tasks-azure-arm-rest\module.json
##[debug]Resource file has already set to: D:\a\_tasks\AzureFunctionApp_501dd25d-1785-43e4-b4e5-a5c78ccc0573\2.244.3\node_modules\azure-pipelines-tasks-azure-arm-rest\module.json
##[debug]Resource file has already set to: D:\a\_tasks\AzureFunctionApp_501dd25d-1785-43e4-b4e5-a5c78ccc0573\2.244.3\node_modules\azure-pipelines-tasks-azure-arm-rest\module.json
##[debug]Resource file has already set to: D:\a\_tasks\AzureFunctionApp_501dd25d-1785-43e4-b4e5-a5c78ccc0573\2.244.3\node_modules\azure-pipelines-tasks-azure-arm-rest\module.json
##[debug]Resource file has already set to: D:\a\_tasks\AzureFunctionApp_501dd25d-1785-43e4-b4e5-a5c78ccc0573\2.244.3\node_modules\azure-pipelines-tasks-azure-arm-rest\module.json
##[debug]Resource file has already set to: D:\a\_tasks\AzureFunctionApp_501dd25d-1785-43e4-b4e5-a5c78ccc0573\2.244.3\node_modules\azure-pipelines-tasks-azure-arm-rest\module.json
##[debug]Resource file has already set to: D:\a\_tasks\AzureFunctionApp_501dd25d-1785-43e4-b4e5-a5c78ccc0573\2.244.3\node_modules\azure-pipelines-tasks-azure-arm-rest\module.json
##[debug]check path : D:\a\_tasks\AzureFunctionApp_501dd25d-1785-43e4-b4e5-a5c78ccc0573\2.244.3\task.json
##[debug]adding resource file: D:\a\_tasks\AzureFunctionApp_501dd25d-1785-43e4-b4e5-a5c78ccc0573\2.244.3\task.json
##[debug]system.culture=en-US
##[debug]Deployment Failed with Error: Error: Input required: azureSubscription
##[debug]task result: Failed
##[error]Error: Input required: azureSubscription
##[debug]Processed: ##vso[task.issue type=error;source=TaskInternal;correlationId=b6d64225-d691-4996-82ee-8b9c1f2d7fe1;]Error: Input required: azureSubscription
##[debug]Processed: ##vso[task.complete result=Failed;]Error: Input required: azureSubscription
##[debug]Deployment failed

Full task logs with system.debug enabled

 2024-08-26T14:41:32.4000157Z ##[debug]Evaluating condition for step: 'AzureFunctionApp'
2024-08-26T14:41:32.4001073Z ##[debug]Evaluating: SucceededNode()
2024-08-26T14:41:32.4001331Z ##[debug]Evaluating SucceededNode:
2024-08-26T14:41:32.4001794Z ##[debug]=> True
2024-08-26T14:41:32.4002070Z ##[debug]Result: True
2024-08-26T14:41:32.4002366Z ##[section]Starting: AzureFunctionApp
2024-08-26T14:41:32.4009893Z ==============================================================================
2024-08-26T14:41:32.4010061Z Task         : Azure Functions Deploy
2024-08-26T14:41:32.4010162Z Description  : Update a function app with .NET, Python, JavaScript, PowerShell, Java based web applications
2024-08-26T14:41:32.4010317Z Version      : 2.244.3
2024-08-26T14:41:32.4010389Z Author       : Microsoft Corporation
2024-08-26T14:41:32.4010490Z Help         : https://aka.ms/azurefunctiontroubleshooting
2024-08-26T14:41:32.4010596Z ==============================================================================
2024-08-26T14:41:32.4679228Z ##[debug]Using node path: C:\agents\3.243.0\externals\node20_1\bin\node.exe
2024-08-26T14:41:32.6093116Z ##[debug]agent.TempDirectory=D:\a\_temp
2024-08-26T14:41:32.6094832Z ##[debug]loading inputs and endpoints
2024-08-26T14:41:32.6096462Z ##[debug]loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN
2024-08-26T14:41:32.6122355Z ##[debug]loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION
2024-08-26T14:41:32.6125508Z ##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION
2024-08-26T14:41:32.6131662Z ##[debug]loading INPUT_APPNAME
2024-08-26T14:41:32.6135287Z ##[debug]loading INPUT_APPSETTINGS
2024-08-26T14:41:32.6138912Z ##[debug]loading INPUT_APPTYPE
2024-08-26T14:41:32.6151273Z ##[debug]loading INPUT_DEPLOYMENTMETHOD
2024-08-26T14:41:32.6152012Z ##[debug]loading INPUT_DEPLOYTOSLOTORASE
2024-08-26T14:41:32.6152560Z ##[debug]loading INPUT_ISFLEXCONSUMPTION
2024-08-26T14:41:32.6157252Z ##[debug]loading INPUT_PACKAGE
2024-08-26T14:41:32.6162896Z ##[debug]loading INPUT_SLOTNAME
2024-08-26T14:41:32.6176297Z ##[debug]loading SECRET_IDENTITYAPIUSERPASSWORD
2024-08-26T14:41:32.6180974Z ##[debug]loading SECRET_SENDGRIDAPIKEY
2024-08-26T14:41:32.6185060Z ##[debug]loading SECRET_SYSTEM_ACCESSTOKEN
2024-08-26T14:41:32.6207591Z ##[debug]loaded 14
2024-08-26T14:41:32.6218655Z ##[debug]Agent.ProxyUrl=undefined
2024-08-26T14:41:32.6220880Z ##[debug]Agent.CAInfo=undefined
2024-08-26T14:41:32.6221516Z ##[debug]Agent.ClientCert=undefined
2024-08-26T14:41:32.6222191Z ##[debug]Agent.SkipCertValidation=undefined
2024-08-26T14:41:32.6570858Z ##[debug]agent.proxyurl=undefined
2024-08-26T14:41:32.6571903Z ##[debug]VSTS_ARM_REST_IGNORE_SSL_ERRORS=undefined
2024-08-26T14:41:32.6572566Z ##[debug]AZURE_HTTP_USER_AGENT=VSTS_0a260fa7-f57f-45d9-ac9b-c8145c5a6af8_build_37_0
2024-08-26T14:41:32.8781851Z ##[debug]Using msalv2
2024-08-26T14:41:32.9507633Z ##[debug]check path : D:\a\_tasks\AzureFunctionApp_501dd25d-1785-43e4-b4e5-a5c78ccc0573\2.244.3\node_modules\azure-pipelines-tasks-azure-arm-rest\module.json
2024-08-26T14:41:32.9564383Z ##[debug]adding resource file: D:\a\_tasks\AzureFunctionApp_501dd25d-1785-43e4-b4e5-a5c78ccc0573\2.244.3\node_modules\azure-pipelines-tasks-azure-arm-rest\module.json
2024-08-26T14:41:32.9587322Z ##[debug]system.culture=en-US
2024-08-26T14:41:32.9630994Z ##[debug]Agent.TempDirectory=D:\a\_temp
2024-08-26T14:41:32.9653880Z ##[debug]Resource file has already set to: D:\a\_tasks\AzureFunctionApp_501dd25d-1785-43e4-b4e5-a5c78ccc0573\2.244.3\node_modules\azure-pipelines-tasks-azure-arm-rest\module.json
2024-08-26T14:41:32.9677250Z ##[debug]Resource file has already set to: D:\a\_tasks\AzureFunctionApp_501dd25d-1785-43e4-b4e5-a5c78ccc0573\2.244.3\node_modules\azure-pipelines-tasks-azure-arm-rest\module.json
2024-08-26T14:41:32.9699510Z ##[debug]Resource file has already set to: D:\a\_tasks\AzureFunctionApp_501dd25d-1785-43e4-b4e5-a5c78ccc0573\2.244.3\node_modules\azure-pipelines-tasks-azure-arm-rest\module.json
2024-08-26T14:41:32.9722623Z ##[debug]Resource file has already set to: D:\a\_tasks\AzureFunctionApp_501dd25d-1785-43e4-b4e5-a5c78ccc0573\2.244.3\node_modules\azure-pipelines-tasks-azure-arm-rest\module.json
2024-08-26T14:41:32.9747022Z ##[debug]Resource file has already set to: D:\a\_tasks\AzureFunctionApp_501dd25d-1785-43e4-b4e5-a5c78ccc0573\2.244.3\node_modules\azure-pipelines-tasks-azure-arm-rest\module.json
2024-08-26T14:41:32.9774309Z ##[debug]Resource file has already set to: D:\a\_tasks\AzureFunctionApp_501dd25d-1785-43e4-b4e5-a5c78ccc0573\2.244.3\node_modules\azure-pipelines-tasks-azure-arm-rest\module.json
2024-08-26T14:41:33.1044258Z ##[debug]Resource file has already set to: D:\a\_tasks\AzureFunctionApp_501dd25d-1785-43e4-b4e5-a5c78ccc0573\2.244.3\node_modules\azure-pipelines-tasks-azure-arm-rest\module.json
2024-08-26T14:41:33.1131773Z ##[debug]Resource file has already set to: D:\a\_tasks\AzureFunctionApp_501dd25d-1785-43e4-b4e5-a5c78ccc0573\2.244.3\node_modules\azure-pipelines-tasks-azure-arm-rest\module.json
2024-08-26T14:41:33.4700277Z ##[debug]check path : D:\a\_tasks\AzureFunctionApp_501dd25d-1785-43e4-b4e5-a5c78ccc0573\2.244.3\task.json
2024-08-26T14:41:33.4701655Z ##[debug]adding resource file: D:\a\_tasks\AzureFunctionApp_501dd25d-1785-43e4-b4e5-a5c78ccc0573\2.244.3\task.json
2024-08-26T14:41:33.4703996Z ##[debug]system.culture=en-US
2024-08-26T14:41:33.4704589Z ##[debug]Deployment Failed with Error: Error: Input required: azureSubscription
2024-08-26T14:41:33.4705129Z ##[debug]task result: Failed
2024-08-26T14:41:33.4742957Z ##[error]Error: Input required: azureSubscription
2024-08-26T14:41:33.4750869Z ##[debug]Processed: ##vso[task.issue type=error;source=TaskInternal;correlationId=b6d64225-d691-4996-82ee-8b9c1f2d7fe1;]Error: Input required: azureSubscription
2024-08-26T14:41:33.4758587Z ##[debug]Processed: ##vso[task.complete result=Failed;]Error: Input required: azureSubscription
2024-08-26T14:41:33.4759517Z ##[debug]Deployment failed
2024-08-26T14:41:33.4898429Z ##[section]Finishing: AzureFunctionApp

Repro steps

name: Deploy Function

trigger:
    branches:
        include:
        - bundle/*
        - main

variables:
    - group: 'XXX.Notifications'
    - name: functionAppName
      value: 'notifications'
    - name: functionResourceGroup
      value: 'notifications-rg'

stages:
-   stage: buildStage
    displayName: Build
    jobs:
    -   job: buildJob
        displayName: Build

        pool:
            vmImage: windows-latest

        steps:
        - checkout: self
          displayName: 'Checkout'
          fetchDepth: 0
          fetchTags: true
          clean: true
        - task: UseDotNet@2
          displayName: "Setup .NET 8"
          inputs:
            packageType: 'sdk'
            version: '8.x'
        - task: gitversion/setup@1
          displayName: GitVersion Setup
          inputs:
            versionSpec: '5.x'
        - task: gitversion/execute@1
          displayName: GitVersion Execute
          name: gitVersion
          inputs:
            disableShallowCloneCheck: true
            useConfigFile: true
            configFilePath: 'GitVersion.yml'
        - task: DotNetCoreCLI@2
          displayName: Restore
          inputs:
            command: 'restore'
            projects: '**/*.csproj'
        - task: DotNetCoreCLI@2
          displayName: Build
          inputs:
            command: 'build'
            projects: '**/*.csproj'
            arguments: '--no-restore --configuration Release /p:DeployOnBuild=true /p:DeployTarget=Package;CreatePackageOnPublish=true'
        - task: PowerShell@2
          displayName: Compress
          inputs:
            targetType: 'inline'
            script: |
              $publishFolders = Get-ChildItem -Directory -Recurse -Filter 'src' | Get-ChildItem -Directory -Recurse -Filter 'Release' | Get-ChildItem -Directory -Recurse -Filter 'Publish'

              foreach ($folder in $publishFolders) { 
                $zipFileName="$(Build.ArtifactStagingDirectory)/$($folder.Parent.Parent.Parent.Parent.Name).zip"
                Compress-Archive -Path "$($folder.FullName)/*" -DestinationPath $zipFileName -CompressionLevel Optimal;  
              }
        - task: PublishBuildArtifacts@1
          displayName: 'Publish Artifact'
          inputs:
            PathtoPublish: '$(Build.ArtifactStagingDirectory)'
            ArtifactName: 'notifications'

-   stage: deploy
    displayName: deploy
    dependsOn: buildStage

    jobs:

    - job: deploy
      displayName: Deploy
      pool:
          vmImage: windows-latest

      variables:
        - ${{ if ne(variables['Build.SourceBranch'], 'refs/heads/main') }}:
          - group: qaGroup
        - ${{ if or(eq(variables['Build.SourceBranch'], 'refs/heads/main'), eq(variables['Build.SourceBranch'], 'refs/heads/work/prodPipeline')) }}:
          - group: prodGroup
        - name: azureConnector
          value: $[variables.AzureServiceConnection]
        - name: environmentName
          value: $[variables.Environment]
        - name: branchTag
          value: $[stageDependencies.buildStage.buildJob.outputs['gitVersion.SemVer']]
        - name: branchName
          value: $[replace(variables['Build.SourceBranch'], 'refs/heads/', '')]

      steps:
        - checkout: self
          persistCredentials: true
        - task: DownloadPipelineArtifact@2
          inputs:
            buildType: 'current'
            artifactName: 'notifications'
            targetPath: '$(Pipeline.Workspace)'
        - task: AzureFunctionApp@2
          inputs:
            connectedServiceNameARM: '$(azureConnector)'
            appType: 'functionApp'
            appName: 'func-XXX-$(environmentName)-notifications'
            package: '$(Pipeline.Workspace)/XXX.Notifications.zip'
            appSettings: '-Version "$(branchTag)" -IdentityApiUri "$(IdentityApiUri)" -IdentityApiUserLogin "$(IdentityApiUserLogin)" -IdentityApiUserPassword "$(IdentityApiUserPassword)" -SendGridApiKey "$(SendGridApiKey)" -OrderStatusChangedTemplateId "$(OrderStatusChangedTemplateId)" -SendGridVerifiedSender "$(SendGridVerifiedSender)" -MakorSourceApiUri "$(MakorSourceApiUri)" -AccountLockedMessageTemplateId "$(AccountLockedMessageTemplateId)" -ResetPasswordMessageTemplateId "$(ResetPasswordMessageTemplateId)"'
            deploymentMethod: 'runFromPackage'
        - script: |
            git checkout $(branchNamee)
            git tag v$(branchTag)
            git push origin v$(branchTag)
v-schhabra commented 2 weeks ago

@FinVamp1 Could you or team please check this issue?

FinVamp1 commented 2 weeks ago

I've assigned this to myself to check.