Azure DevOps 摘要 中文乱码

问题

最近在开发Azure Devops 流水线任务插件时,发现在流水线CI中把结果推到摘要中显示,如果包含中文就会乱码

使用azure devops pipelines task api, 参考网址 https://github.com/microsoft/azure-pipelines-tasks/blob/master/docs/authoring/commands.md

export function uploadBuildSummary(summaryPath: string, title: string): void {
    tl.debug(`[SQ] Uploading build summary from ${summaryPath}`);
    tl.command(
        'task.addattachment',
        {
            type: 'Distributedtask.Core.Summary',
            name: title
        },
        summaryPath
    );
}

实际运行的过程中,是用了##vso命令

console.log(`##vso[task.addattachment type=Distributedtask.Core.Summary;name=${sectionName};]${markdownFilePath}`);

为了方便问题的复现,以下分别在CI和CD中用bash创建一个流水线任务,脚本如下:

echo '**我是中文** i am english' > $(BUILD.ARTIFACTSTAGINGDIRECTORY)/test.md

cat $(BUILD.ARTIFACTSTAGINGDIRECTORY)/test.md

echo '##vso[task.addattachment type=Distributedtask.Core.Summary;name=中文标题;]$(BUILD.ARTIFACTSTAGINGDIRECTORY)/test.md'
  1. CI 乱码

  2. CD 中不乱码

问题分析

  1. 乱码恢复
    https://toolskk.com/garbled-text-recover

  2. http请求分析

  3. 进入代理机,查看文件编码

类似的问题:https://github.com/microsoft/azure-pipelines-tasks/issues/10375
参考解决方案:https://github.com/lakshaykaushik/PublishHTMLReport

最终

给微软提了Case后,他们的产品组承认这是一个Bug,到目前还没有发布补丁包,如果有踩坑的小伙伴记得使用英文字符来规避这个问题。

原文地址:https://www.cnblogs.com/smallidea/p/14589716.html