【问题标题】:Setting up build variable "version" breaks Azure Functions CLI func extensions sync设置构建变量“版本”会中断 Azure Functions CLI func extensions 同步
【发布时间】:2019-08-06 12:13:38
【问题描述】:

使用 Azure 函数 CLI 命令未正确构建 Azure 函数:func extensions 在以 yaml 编写的 Azure 构建管道中同步,其中声明了变量“版本”:

pool:
  name: Dev
variables:
  version: $(Build.BuildNumber)
steps:
  - task: Npm@1
    displayName: "NPM Install function app"
    inputs:
      workingDir: src
      command: install
  - powershell: "dotnet restore"
    workingDirectory: src
  - powershell: "func extensions sync --javascript"
    workingDirectory: src

在“func extensions sync”调用失败并显示此错误消息:

Restore completed in 34.26 ms for /home/vsts/work/1/s/src/extensions.csproj.
obj/Debug/netcoreapp2.2/extensions.AssemblyInfo.cs(12,59): warning CS7035: The specified version string does not conform to the recommended format - major.minor.build.revision [/home/vsts/work/1/s/src/extensions.csproj]
obj/Debug/netcoreapp2.2/extensions.AssemblyInfo.cs(16,55): error CS7034: The specified version string does not conform to the required format - major[.minor[.build[.revision]]] [/home/vsts/work/1/s/src/extensions.csproj]

Build FAILED.

我知道 $version 变量设置为 20190806.19

结果是构建工件中没有加载任何二进制文件,这会阻止 Azure 函数的成功部署。

我知道删除版本变量声明可以修复 Azure Function cli 调用。

这可以通过在环境中设置版本变量在本地重现。

但是,我需要此变量才能使用 FileTransform 任务在 package.json 文件中进行替换。

似乎 func extensions sync 生成了错误的 extensions.AssemblyInfo.cs(这是输出示例):

//------------------------------------------------------------------------------
// <auto-generated>
//     Generated by the MSBuild WriteCodeFragment class.
// </auto-generated>    
//------------------------------------------------------------------------------

using System;
using System.Reflection;

[assembly: System.Reflection.AssemblyCompanyAttribute("extensions")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("20190806.19.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("20190806.19")]
[assembly: System.Reflection.AssemblyProductAttribute("extensions")]
[assembly: System.Reflection.AssemblyTitleAttribute("extensions")]
[assembly: System.Reflection.AssemblyVersionAttribute("20190806.19.0.0")]

有解决方法吗? 这是我可以在项目 GitHub 中提出的问题,还是我遗漏了一些细节?

【问题讨论】:

    标签: azure azure-functions azure-pipelines


    【解决方案1】:

    一种解决方法是在运行扩展同步后设置环境变量:

    - powershell: $env:version=$(Build.BuildNumber)
    - task: FileTransform@1
      inputs:
        folderPath: src
        targetFiles: "package.json"
        fileType: json
    

    不是很优雅,但它确实有效......

    【讨论】:

      猜你喜欢
      • 2020-02-05
      • 1970-01-01
      • 1970-01-01
      • 2019-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-04
      相关资源
      最近更新 更多