首页 > 解决方案 > 天蓝色管道模板在 targetType:filePath 时找不到脚本

问题描述

我有一个运行在不同存储库中的管道模板的 azure 管道......当模板执行任务时:带有内联 shell 脚本的 Bash@3 一切都很好......但是我希望模板在本地执行脚本到模板存储库...目前当我使用它时找不到此脚本targetType: filePath...此脚本位于与管道模板 yaml 文件相同的存储库目录的本地

这是我的父管道,位于https://github.com/sekhemrekhutawysobekhotep/shared_variables_across_templates

cat ~/src/foo/github.com/sekhemrekhutawysobekhotep/shared_variables_across_templates/parent_own_file.yaml


pool:
  vmImage: 'ubuntu-latest'

resources:
  repositories:
  - repository: cool_templates
    type: github  #  use these flavors    git = Azure DevOps / github = GitHub
    name: sekhemrekhutawysobekhotep/pipeline-templates
    ref: main
    endpoint: sekhemrekhutawysobekhotep

trigger:
  branches:
    exclude:
      - '*'

stages:
- template: do_peach.yaml@cool_templates

上面调用了位于https://github.com/sekhemrekhutawysobekhotep/pipeline-templates的管道模板 do_peach.yaml ...这是该管道模板

cat ~/src/foo/github.com/sekhemrekhutawysobekhotep/pipeline-templates/do_peach.yaml  


stages:
- stage: some_cool_template
  jobs:
  - job: launch_template_rwanda
    steps:
    - task: Bash@3
      displayName: 'now lets do some calc'
      inputs:
        targetType: filePath
        # filePath: ./do_peach.sh
        filePath: do_peach.sh

do_peach.sh当找不到与 do_peach.yaml 位于同一存储库中的脚本时,上述管道模板错误

##[error]ENOENT: no such file or directory, stat '/home/vsts/work/1/s/do_peach.sh'

这是天蓝色管道运行的输出

https://dev.azure.com/sekhemrekhutawysobekhotep/public_project/_build/results?buildId=547&view=logs&j=31e0a65e-b3f0-5eb0-8d0a-15a2530340ec&t=bb044a8a-7c80-5775-3c93-f233af567bd5&l=44

我的猜测是我需要加强我如何指定给标记文件路径的值:在上面......似乎这应该是一个常见问题,因为我经常遇到这个错误,这次我不想将我的 shell 脚本内联为它不适合(我收到错误 Exceeded max expression length 21000,但这是另一个问题)...管道模板上的文档不提供解决方案...有什么建议吗?

PS当两个存储库中的代码都作为 azure repos 而不是 github 时,我得到同样的错误

试图蛮力找到文件 do_peach.sh 我在下面运行但找不到文件

find $(Agent.BuildDirectory) | grep 'do_peach.sh' 


find $(Build.SourcesDirectory) | grep 'do_peach.sh' 

标签: azureazure-pipelines

解决方案


请加:

- checkout: cool_templates

下载存储库。同样对于多个存储库,代码将位于单独的文件夹中

多个存储库:如果您的作业中有多个签出步骤,您的源代码将签出到以存储库命名的目录中,作为 (Agent.BuildDirectory) 中 s 的子文件夹。如果 (Agent.BuildDirectory) 是 C:\agent_work\1 并且您的存储库被命名为 tools 和 code,那么您的代码将检出到 C:\agent_work\1\s\tools 和 C:\agent_work\1\s\code。


推荐阅读