Azure Devops 脚本不会执行 2 个 yarn 命令
Azure Devops Script won't execute 2 yarn commands
Azure devops 构建管道。
我们发现了一个奇怪的问题,即 script
块中的任何 yarn
命令都会在 yarn 命令之后终止该脚本块。
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
所以我们永远不会echo "*********3*********"
即使是像这样简单的东西:
- script: |
echo "Start"
yarn -v
echo "We never get here"
Cmdline 任务似乎在第一个 yarn 任务之后就停止了。
这是在本地 Windows Server 2016 上 运行ning。如果我们 运行 在 ubuntu 虚拟机上运行相同的脚本,它工作正常。
问题是 yarn
不是可执行文件,它是批处理文件。
根据documentation,调用批处理文件时应使用call
:
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 ...
Azure devops 构建管道。
我们发现了一个奇怪的问题,即 script
块中的任何 yarn
命令都会在 yarn 命令之后终止该脚本块。
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
所以我们永远不会echo "*********3*********"
即使是像这样简单的东西:
- script: |
echo "Start"
yarn -v
echo "We never get here"
Cmdline 任务似乎在第一个 yarn 任务之后就停止了。
这是在本地 Windows Server 2016 上 运行ning。如果我们 运行 在 ubuntu 虚拟机上运行相同的脚本,它工作正常。
问题是 yarn
不是可执行文件,它是批处理文件。
根据documentation,调用批处理文件时应使用call
:
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 ...