我有一个 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.yaml 位于同一存储库中的脚本 do_peach.sh
时出现错误
##[error]ENOENT: no such file or directory, stat '/home/vsts/work/1/s/do_peach.sh'
这是 azure 管道运行的输出
我的猜测是我需要加强如何指定标签 filePath: 的值,在上面......似乎这应该是一个常见问题,因为我经常遇到这个错误,这次我不想把我的 shell内联脚本,因为它不适合(我收到错误 Exceeded max expression length 21000
但这是另一个问题)...管道模板上的文档没有提供解决方案...有什么建议吗?
PS 当两个存储库中的代码都作为 azure 存储库而不是 github 运行时,我遇到相同的错误
为了尝试暴力查找文件 do_peach.sh,我在下面运行但未能找到该文件
find $(Agent.BuildDirectory) | grep 'do_peach.sh'
find $(Build.SourcesDirectory) | grep 'do_peach.sh'
最佳答案
请添加:
- checkout: cool_templates
下载存储库。此外,对于多个存储库,代码将位于单独的 folder 中
Multiple repositories: If you have multiple checkout steps in your job, your source code is checked out into directories named after the repositories as a subfolder of s in (Agent.BuildDirectory). If (Agent.BuildDirectory) is C:\agent_work\1 and your repositories are named tools and code, your code is checked out to C:\agent_work\1\s\tools and C:\agent_work\1\s\code.
关于当 targetType : filePath 时, azure 管道模板无法找到脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68628601/