Search code examples
c#azureazure-functionsyamldevops

Problem deploying Azure Function Code to a FunctionApp Slot using yaml (zip not found)


I am building an Azure Function in C# and wish to deploy using pipeline. I build once, test, then publish. Then, for each ENV, I run a bicep file to setup infrastructure and immediately after I wish to deploy the published Function Code to the (single) Function App.

I get an error trying to deploy from the published zip file. The file can't be found. What am I doing wrong?


Example of published file:

[command]/usr/bin/zip -r /home/vsts/work/1/s/build272.zip

(The log lines seem reasonable)

Error seen :

##[error]Error: No package found with specified pattern: /home/vsts/work/1/a/*.zip
Check if the package mentioned

Note that we publish from /1/s and try to find it in /1/a

The build has 'attached' artifacts as 'drop/build272.zip (The 11MB file seems reasonable)

yaml lines to publish:

- task: DotNetCoreCLI@2
  displayName: "dotnet publish"
  inputs:
    command: publish
    arguments: '--configuration Release --output publish_output'
    projects: 'src/**/*.csproj'
    publishWebProjects: false
    modifyOutputPath: false
    zipAfterPublish: false
- task: ArchiveFiles@2
  displayName: "Archive files (into zip)"
  inputs:
    rootFolderOrFile: "$(System.DefaultWorkingDirectory)/publish_output"
    includeRootFolder: false
    archiveFile: "$(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip"
- task: PublishBuildArtifacts@1
  displayName: "Publish build artifacts"
  inputs:
    PathtoPublish: '$(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip'

yaml lines to deploy :

- task: AzureFunctionApp@1 # Add this at the end of your file
  displayName: 'Deploy Function code to FunctionApp Slot'
  inputs:    
    azureSubscription: 'ServiceConnection'
    appType: functionAppLinux # default is functionApp
    appName: 'f2404dev-app'
    package: '$(System.ArtifactsDirectory)/**/*.zip'

Solution

  • It seems that you are missing the download artifact step

    - task: DownloadBuildArtifacts@1
      inputs:
        buildType: 'current'
        downloadType: 'single'
        artifactName: 'drop'
        itemPattern: '**/*.zip'
      downloadPath: '$(System.ArtifactsDirectory)'
    

    Reference: https://sterl.org/2023/03/azure-devops-function-app-deployment-no-package-found/