Azure Devops 脚本不会执行 2 个纱线命令 [英] Azure Devops Script won't execute 2 yarn commands

查看:31
本文介绍了Azure Devops 脚本不会执行 2 个纱线命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们看到一个奇怪的问题,script 块中的任何 yarn 命令都会在 yarn 命令之后终止该脚本块.

We are seeing a weird issue where any yarn command in a script block will terminate that script block after the yarn command.

  steps:
    - script: |
        echo "*********1*********"
        cd D:\my\src
        echo "*********2*********"
        yarn add --dev jest-junit
        echo "*********3*********"
        yarn test:unit --silent --ci --reporters=jest-junit
        echo "*********4*********"

将产生此输出:

"*********1*********"
"*********2*********"
yarn add v1.16.0
[1/4] Resolving packages...
...
Done in 107.91s.
Finishing: CmdLine

所以我们永远不会去回声******3*********"

即使是这样简单的事情:

Even something like simple like this:

  - script: |
      echo "Start"
      yarn -v
      echo "We never get here"

似乎 Cmdline 任务在第一个 yarn 任务之后就停止了.

It seems the Cmdline task just stops after the first yarn task.

这是在内部部署的 Windows Server 2016 上运行的.如果我们在 ubuntu 虚拟机上运行相同的脚本,它就可以正常工作.

This is running on an on-premise Windows Server 2016. If we run the same script on an ubuntu vm it works fine.

推荐答案

问题在于 yarn 不是可执行文件,而是批处理文件.

The problem is that yarn is not an executable, it's a batch file.

根据 文档,调用批处理文件时应该使用call:

According to the documentation, you should use call when calling a batch file:

Azure Pipelines 将您的内联脚本内容放入一个临时批处理文件 (.cmd) 中以运行它.当你想在 Windows CMD 中从另一个批处理文件运行一个批处理文件时,你必须使用 call 命令,否则第一个批处理文件被终止.这将导致 Azure Pipelines 运行您的预期脚本,直到第一个批处理文件,然后运行批处理文件,然后结束该步骤.第一个脚本中的其他行不会运行.在 Azure Pipelines 脚本步骤中执行批处理文件之前,应始终预先调用.

Azure Pipelines puts your inline script contents into a temporary batch file (.cmd) in order to run it. When you want to run a batch file from another batch file in Windows CMD, you must use the call command, otherwise the first batch file is terminated. This will result in Azure Pipelines running your intended script up until the first batch file, then running the batch file, then ending the step. Additional lines in the first script wouldn't be run. You should always prepend call before executing a batch file in an Azure Pipelines script step.

所以在你的情况下,yarn ... 应该改为 call yarn ...

So in your case, yarn ... should be changed to call yarn ...

这篇关于Azure Devops 脚本不会执行 2 个纱线命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆