Azure Function部署报错:Failed to read central dir file header due to signature mismatch
问题描述
场景背景
我有一个DevOps流水线,用于构建C# Azure Function并部署至现有Windows S1 App Service计划。
流水线构建与发布任务
- 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
部署任务
- 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
Kudu日志错误信息
<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>
Function App应用设置
{ "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 }
用户疑问
我已从DevOps工件手动下载该Zip文件,可正常解压且包含预期的.NET文件。请问是什么原因导致“Failed to read central dir file header due to signature mismatch”错误?
问题分析与解决方案
Zip包在Azure侧存储/传输损坏
本地解压正常不代表Azure获取到的包完整,可能是部署时包传输中断或SitePackages目录写入不完整。- 调整部署任务的
package参数,直接指向工件中的Zip包,例如改为$(Pipeline.Workspace)/${{parameters.artifactName}}/*.zip,避免变量路径解析错误 - 将应用设置
WEBSITE_ENABLE_SYNC_UPDATE_SITE改为false,关闭同步更新防止文件写入不完整
- 调整部署任务的
Run From Package模式的Zip格式兼容性问题
WEBSITE_RUN_FROM_PACKAGE=1使用ZipFS直接挂载包,对Zip格式的规范度要求更高,本地解压工具兼容性更强可能掩盖格式问题。- 在
DotNetCoreCLI@2的publish任务参数中添加-p:ZipPackageCompressionLevel=Optimal,确保生成符合Azure要求的Zip格式 - 改用
deploymentMethod: zipDeploy部署方式,先解压包再部署,绕过ZipFS挂载的格式校验
- 在
流水线打包逻辑异常
多项目打包可能导致Zip包结构不符合Azure Function的要求。- 明确指定单个Function项目路径作为
projects参数值,排除无关项目干扰 - 暂时移除
--no-build参数,确保publish基于最新构建输出,避免缓存文件混入导致包结构异常
- 明确指定单个Function项目路径作为
内容的提问来源于stack exchange,提问作者Rob Bowman
相关产品推荐
相关产品推荐

