如何在 Azure DevOps YAML 构建定义的一个构建过程中使用两个脚本命令?

How can I have two script commands in one build process for Azure DevOps YAML build definitions?

(有 controversy going on,但这应该足以定义问题。)

我们发现自己在一个构建路径(即一个 YAML (.yml) 文件)中需要三个脚本作业。我试过了:

Steps:
- script: step1 1>&2
# # Do this after other tasks such as building
- task: DotNetCoreCLI@2
  inputs:
    command: test
    projects: 'TEST/*/*.csproj'
    arguments: '--configuration Release'
  displayName: 'Run Unit Tests'
- script: step2 1>&2
- script: step3 1>&2

但是当 steps 下有多个 - script 时,构建会出现问题。通常我会把它们堆成一个脚本之类的,但我不能,因为中间有一个测试工作。我该如何制作这个东西运行?

我复制并粘贴回来,它开始工作了。它一定是文件中的不可打印字符。

在管道作业中,您在脚本任务中设置的脚本将被打包为相应的脚本文件到代理上运行。每个脚本任务的脚本文件都是独立的,流水线不会将所有的脚本打包成一个脚本文件。

Normally I'd just pile them into one script and all that, but I can't because there's a test job in the middle.

对于您的情况,您可以尝试直接执行 'dotnet test' command in the script task instead of using the .NET Core CLI task.

通过这种方式,您可以为'step1'、'dotnet test'编写脚本, 'step2' 和 'step3' 合并成一个脚本文件,只用一个脚本执行这个脚本文件管道中的任务。

I copy/pasted 来自 MSDN 文档的原始脚本行。在添加第二个脚本行时,我从 yml 解析器(我没有捕获)中得到一个无意义的错误,其中第二个脚本 - 指示符的位置作为错误的位置,脚本行的一部分作为错误体。然后我copy/pasted进Whosebug问问题。

在 copy/paste 从 Whosebug 返回时,错误不再出现。唯一合理的解释是从 msdn 的原始 copy/paste 中获取了一个不可打印的字符,该字符在后续步骤中被吃掉了。