更改 Azure Pipelines YAML 中所有步骤的工作目录

Changing the working directory for all steps in Azure Pipelines YAML

可以为单独的脚本设置工作目录:

- script: foo
  workingDirectory: bar

但是,如果所有步骤都旨在 运行 在特定目录中,则为每个步骤定义它变得重复。

使用cd不影响其他步骤:

- script: cd foo
- script: pwd # returns default working dir instead of foo

这个问题很重要的两个具体例子是:

我想这会把与只读的 ADO 中的 predefined variables 相关的事情搞砸 - 所以我认为这是不可能的。

在管道开始时立即检查源或将内容复制到默认工作目录可能会更好。

解决方法是将文件移动到默认工作目录,而不是更改任务的工作目录,一个方便的方法是使用 git-sparse-checkout,如下所示:

git sparse-checkout set example && mv example/{*,.*} . || true

{*,.*} 部分也用于移动点文件,并且需要 || true 因为它也尝试移动 ....