【问题标题】:Changing the working directory for all steps in Azure Pipelines YAML更改 Azure Pipelines YAML 中所有步骤的工作目录
【发布时间】:2021-08-06 18:25:51
【问题描述】:

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

- script: foo
  workingDirectory: bar

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

使用cd不影响其他步骤:

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

有关此问题的两个具体示例是:

  • 当检出多个 repos 作为资源时,默认工作目录比检出的 repos 高一级
  • 为位于子目录中的项目(例如在 monorepo 中)运行管道时

【问题讨论】:

    标签: azure-devops yaml azure-pipelines azure-pipelines-yaml


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:

      我想这会弄乱与 ADO 中的 predefined variables 相关的事情,因为它是只读的 - 所以我认为这是不可能的。

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

      【讨论】:

        猜你喜欢
        • 2019-05-20
        • 1970-01-01
        • 2021-03-22
        • 1970-01-01
        • 1970-01-01
        • 2020-06-04
        • 2020-03-05
        • 2019-08-09
        • 2021-10-24
        相关资源
        最近更新 更多