步骤中破坏单个命令

步骤中破坏单个命令

本文介绍了如何在多行“脚本"步骤中破坏单个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个使用Azure Pipeline的项目,它依赖于回购根目录下的 azure-pipelines.yml 文件.

We have a project using Azure Pipeline, relying on azure-pipelines.yml file at the repo's root.

实施 script 步骤时,可以在同一步骤中执行连续的命令,只需将它们写在不同的行上即可.

When implementing a script step, it is possible to execute successive commands in the same step simply writing them on different lines:

- script: |
  ls -la
  pwd
  echo $VALUE

但是,如果我们有一条非常长的命令,我们希望能够在YAML文件中的多行上将其中断,但是找不到相应的语法?

Yet, if we have a single command that is very long, we would like to be able to break it on several lines in the YAML file, but cannot find the corresponding syntax?

推荐答案

您没有指定代理操作系统,因此我在 windows-latest ubuntu-latest .请注意,脚本任务在这两种环境下运行略有不同.在Windows上,它使用cmd.exe.在Ubuntu上,它使用bash.因此,您必须使用正确的语法.

You didn't specify your agent OS so I tested on both windows-latest and ubuntu-latest. Note that the script task runs a bit differently on these 2 environments. On Windows, it uses cmd.exe. On Ubuntu, it uses bash. Therefore, you have to use the correct syntax.

在Windows上:

pool:
  vmImage: 'windows-latest'

steps:
- script: |
    mkdir ^
    test ^
    -p ^
    -v

在Ubuntu上:

pool:
  vmImage: 'ubuntu-latest'

steps:
- script: |
    mkdir \
    test \
    -p \
    -v

上面的两个文件在我的Azure DevOps上工作.

Those two files above work on my Azure DevOps.

这篇关于如何在多行“脚本"步骤中破坏单个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 16:39