如何在Azure Pipelines中指定要运行的Python文件?

编程语言 2026-07-10

我正在运行一个Azure流水线。

我想在仓库中运行一个Python脚本,但在YAML文件中无法正确引用它。

从Azure链接中获取的路径是:https://dev.azure.com/Company/MI/_git/MIR?path=/Test2852/hello_world.py

流水线中的相关区域是:

- task: PythonScript@0
  inputs:
    scriptSource: 'filePath'
    scriptPath: 'https://dev.azure.com/Company/MI/_git/MIR?path=/Test2852/hello_world.py'

但我得到了这个错误

##[error]ENOENT: no such file or directory, stat '/home/vsts/work/1/s/https:/dev.azure.com/Company/MI/_git/MIR?path=/Test2852/hello_world.py'

我尝试了以下 scriptPath 值:

  • scriptPath: '$(System.DefaultWorkingDirectory)/Test2852/hello_world.py'
  • scriptPath: '$(Build.SourcesDirectory)/Test2852/hello_world.py'
  • scriptPath: '$(Pipeline.Workspace)/Test2852/hello_world.py'

它们都返回了相同的错误:

##[error]ENOENT: no such file or directory, stat '/home/vsts/work/1/Test2852/hello_world.py'

应该如何在仓库中正确引用这个Python文件?

解决方案

需要确保被调用的Python脚本与流水线在同一个仓库中,这样脚本路径才能正常工作,而不是引用来自不同仓库的脚本。

scriptPath: '$(System.DefaultWorkingDirectory)/hello_world.py'
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章