Azure Function: Failed to read central dir file header due to signature mismatch

188 views Asked by At

I have a devops pipeline the builds a C# azure function then deploys to an existing Windows S1 app service plan.

The relevant pipeline tasks are shown below:

- task: DotNetCoreCLI@2
    displayName: Build
    inputs:
      command: build
      projects: ${{parameters.projectsToBuild}}
      arguments: ' --configuration ${{parameters.buildConfiguration}} -p:Version="$(build.buildnumber)" -p:SourceRevisionId="$(sourceVersionShort)"'
    
- task: DotNetCoreCLI@2
    displayName: Test
    inputs:
      command: test
      projects: ${{parameters.projectsToTest}}
      arguments: --configuration ${{parameters.buildConfiguration}} --collect "Code coverage"
    
- task: DotNetCoreCLI@2
    displayName: Publish
    condition: ${{parameters.publishArtifacts}}
    inputs:
      command: publish
      projects: |
        ${{parameters.projectsToBuild}}
        !${{parameters.projectsToTest}}
      arguments: '--configuration ${{parameters.buildConfiguration}} --output $(build.artifactstagingdirectory) --no-build'
      publishWebProjects: false
      zipAfterPublish: true
    
- task: PublishBuildArtifacts@1
    displayName: Publish to DevOps
    condition: ${{parameters.publishArtifacts}}
    inputs:
      PathtoPublish: '$(Build.ArtifactStagingDirectory)'
      ArtifactName: "${{parameters.artifactName}}"
      publishLocation: Container

After the zip has been published as a pipeline artifact, it is deployed with the following task:

- task: AzureFunctionApp@1
  displayName: Deploy Az Func
  inputs:
    azureSubscription: sub-name-here
    resourceGroupName: rg-name-here
    appName: app-name-here
    appType: functionApp
    package: ${{variables.packagePath}}
    deploymentMethod: runFromPackage

After the pipeline has completed, the functions have not deployed into the function app. On looking into the function app logs via kudu, I see the following:

<Event>
        <System>
            <Provider Name="ZipFS"/>
            <EventID>0</EventID>
            <Level>1</Level>
            <Task>0</Task>
            <Keywords>Keywords</Keywords>
            <TimeCreated SystemTime="2023-04-26T14:00:04Z"/>
            <EventRecordID>1163925125</EventRecordID>
            <Channel>Application</Channel>
            <Computer>compnamehere</Computer>
            <Security/>
        </System>
        <EventData>
            <Data>ZIP_SUPPORT::OpenZipFile(905): Failed to read central dir file header due to signature mismatch (Path:"\\?\d:\local\SitePackages\1163635875.zip" Err:0x8007026a)</Data>
        </EventData>
    </Event>

The relevant app settings values of the function app are:

{
    "name": "AzureWebJobsStorage",
    "value": "constring is here",
    "slotSetting": false
  },
  {
    "name": "FUNCTIONS_EXTENSION_VERSION",
    "value": "~4",
    "slotSetting": false
  },
  {
    "name": "FUNCTIONS_WORKER_RUNTIME",
    "value": "dotnet-isolated",
    "slotSetting": false
  },
  {
    "name": "WEBSITE_ENABLE_SYNC_UPDATE_SITE",
    "value": "true",
    "slotSetting": false
  },
  {
    "name": "WEBSITE_RUN_FROM_PACKAGE",
    "value": "1",
    "slotSetting": false
  }

I have manually downloaded the zip file from the devops artifacts. I was able to unzip no problem, and it contains the .net files I'd expect.

Any ideas what's causing the Failed to read central dir file header due to signature mismatch error?

2

There are 2 answers

0
Rob Bowman On BEST ANSWER

Will probably never know why I get the zip signature error when usng the AzureFunctionApp@1 task. However, using the tip from @SiddheshDesai, I have a work-around using the AzureCLI@2 task:

- task: AzureCLI@2
  displayName: 'Deploy Az Func using Azure CLI'
  inputs:
    azureSubscription: 'devops-intg-nurseryfees-nonprod-dev-001'
    scriptType: 'bash'
    scriptLocation: 'inlineScript'
    inlineScript: |
      echo "Pipeline.Workspace: $(Pipeline.Workspace)"
      ls -R $(Pipeline.Workspace)
      az functionapp deployment source config-zip \
        --resource-group rg-intg-nurseryfees-dev-001 \
        --name func-intg-nurseryfees-dev-001 \
        --src $(Pipeline.Workspace)/dotnet/AzFunc.zip
6
SiddheshDesai On

I created one Azure Function with dot net 6.0 LTS in my Visual studio and pushed the code to Azure DevOps like below:-

enter image description here

enter image description here

Now, I created a Build Pipeline to deploy this Function in Azure like below by downloading the artifact during build as zip:-

enter image description here

enter image description here

My YAML pipeline script:-

As this is a default template you can refer the below yaml script in this github repository

# .NET Core Function App to Windows on Azure

# Build a .NET Core function app and deploy it to Azure as a Windows function App.

# Add steps that analyze code, save build artifacts, deploy, and more:

# https://docs.microsoft.com/en-us/azure/devops/pipelines/languages/dotnet-core

  

trigger:

- master

  

variables:

# Azure Resource Manager connection created during pipeline creation

azureSubscription: '<subscription-name>'

  

# Function app name

functionAppName: 'siliconfunc32'

  

# Agent VM image name

vmImageName: 'windows-2019'

  

# Working Directory

workingDirectory: '$(System.DefaultWorkingDirectory)/HTTPdotnetazfunc'

  

stages:

- stage: Build

displayName: Build stage

  

jobs:

- job: Build

displayName: Build

pool:

vmImage: $(vmImageName)

  

steps:

- task: DotNetCoreCLI@2

displayName: Build

inputs:

command: 'build'

projects: |

$(workingDirectory)/*.csproj

arguments: --output $(System.DefaultWorkingDirectory)/publish_output
--configuration Release

  

- task: ArchiveFiles@2

displayName: 'Archive files'

inputs:

rootFolderOrFile: '$(System.DefaultWorkingDirectory)/publish_output'

includeRootFolder: false

archiveType: zip

archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip

replaceExistingArchive: true

  

- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip

artifact: drop

  

- stage: Deploy

displayName: Deploy stage

dependsOn: Build

condition: succeeded()

  

jobs:

- deployment: Deploy

displayName: Deploy

environment: 'development'

pool:

vmImage: $(vmImageName)

  

strategy:

runOnce:

deploy:

  

steps:

- task: AzureFunctionApp@1

displayName: 'Azure functions app deploy'

inputs:

azureSubscription: '$(azureSubscription)'

appType: functionApp

appName: $(functionAppName)

package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip' ```

I ran the pipeline and the function app was deployed on Azure successfully like below:-

Build step ran successfully and zip file was created successfully like below:-

enter image description here

My Download artifact and Deploy task was successful like below:-

enter image description here

enter image description here

Function running on Portal:-

enter image description here

Alternatively, You can run below command in your Azure CLI locally. I downloaded the zip file from the artifact generated above and used it:-

I have referred below command from this MS Document:-

az functionapp deployment source config-zip -g resourcegroupname -n \
functionname --src "<path-to-local-zip-file>"

Output:-

enter image description here

UPDATED:-

Release pipeline:-

I tried to deploy the Function app by using its build artifact as a release pipeline below:-

Added the artifact and the repository in my Release pipeline like below:-

enter image description here

enter image description here

Created a task to deploy my code to Function app and selected my Azure function app like below:-

enter image description here

I have set the variable as Dev like below:-

enter image description here

Created new Release:-

enter image description here

Release got successful like below:-

enter image description here

My Application settings:-

enter image description here

I have also checked my Kudu logs and the deployment was successful refer below:-enter image description here

I also downloaded the logs locally and inspected the files but I did not receive any error related to the signature mismatch

It looks like in your case the build step is generating corrupted zip in your pipeline, Can you try the Steps I have mentioned above and the above YAML Script's below steps

  • task: ArchiveFiles@2

displayName: 'Archive files'

inputs:

rootFolderOrFile: '$(System.DefaultWorkingDirectory)/publish_output'

includeRootFolder: false

archiveType: zip

archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip

replaceExistingArchive: true

  • publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip

artifact: drop

As a fresh starter pipeline with correct variables and redeploy your app

My repository code is set to workingDirectory: '$(System.DefaultWorkingDirectory)/HTTPdotnetazfunc' that where HTTPdotnetazfunc is my folder inside the current repository so it zips the correct folder:-

enter image description here