0

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?

Rob Bowman
  • 7,632
  • 22
  • 93
  • 200
  • Refer this SO thread answer it looks your zip file is not a proper zip file or is corrupted thus causing this error - https://stackoverflow.com/questions/7703639/bad-magic-number-error-with-zipfile-module-in-python Also, Refer this link here - https://stackoverflow.com/questions/73948328/error-unzip-end-of-central-directory-signature-not-found for the similar error – SiddheshDesai Apr 27 '23 at 09:45
  • Can you try to upload the same function code zip file by running this command from your azure cli and check if the function trigger is deployed successfully - https://learn.microsoft.com/en-us/azure/azure-functions/deployment-zip-push#cli Just to validate if the function zip file code? – SiddheshDesai Apr 27 '23 at 09:46
  • 1
    @SiddheshDesai thank you for the help. I followed your suggestion. I first took a copy of the zip from the pipeline artefact of the previous deployment. I then ran the "az functionapp deployment"command to upload this zip to the function app. After running, I can confirm that the function app worked ok - confirming that the zip produced by the pipeline is valid – Rob Bowman Apr 27 '23 at 10:38

2 Answers2

1

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

SiddheshDesai
  • 3,668
  • 1
  • 2
  • 11
  • apologies for the mis understanding. The solution you gave in the comment did not work. If the zip from the pipeline is manually uploaded using the command you gave, then the function app works. However, the main problem is, when the same zip is deployed from the pipeline via the AzureFunctionApp@1 task then the function app dos not work – Rob Bowman Apr 27 '23 at 11:22
  • @Rob Bowman Did you check the Deployment steps above? Cause, The Function from zip file got deployed successfully in the above pipeline, It looks like the zip that is generated as Artifact in your pipleline is corrupted. – SiddheshDesai Apr 27 '23 at 11:32
  • @RobBowman I have updated the answer with Release pipeline, Can you try to deploy your function app as release pipeline by using the same build artifact and repo? And check if it gets deployed successfully like above? Check the UPDATED section in the answer – SiddheshDesai Apr 27 '23 at 12:10
  • @RobBowman Some additional information, I am running the pipeline as an Azure subscription with Owner role and My Azure function app is created on .Net 6.0 LTS Windows OS and my local function file is also created on .Net 6.0 in Visual studio. – SiddheshDesai Apr 27 '23 at 12:23
  • That's a great answer. It does work when I create from scratch. I had expected it too because we have several other function apps deployed with the AzureFunctionApp@1 task that work ok. I guess there must be something especially broken with this particular host app service. I have raised a ticket with Microsoft and will report back here on resolution – Rob Bowman Apr 27 '23 at 15:40
  • it can't be the build / publish task that corrupting the zip because if I use the same task and simply swap the AzureFunctionApp@1 task for an AzureCLI@2 task then it works – Rob Bowman May 06 '23 at 17:58
0

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
Rob Bowman
  • 7,632
  • 22
  • 93
  • 200