为了账号安全,请及时绑定邮箱和手机立即绑定

python 在 Azure Pipelines 的“.py”中找不到“__main__”模块

python 在 Azure Pipelines 的“.py”中找不到“__main__”模块

料青山看我应如是 2023-05-16 14:59:19
我的目标是通过 Azure Pipeline 将我的 python 脚本从 GitHub 部署到我的虚拟机并运行。我的azure-pipelines.yml样子是这样的:jobs: - deployment: VMDeploy  displayName: Test_script  environment:    name: deploymentenvironment    resourceType: VirtualMachine  strategy:      rolling:        maxParallel: 2  #for percentages, mention as x%        preDeploy:          steps:          - download: current          - script: echo initialize, cleanup, backup, install certs        deploy:          steps:          - task: Bash@3            inputs:              targetType: 'inline'              script: python3 $(Agent.BuildDirectory)/test_file.py        routeTraffic:          steps:          - script: echo routing traffic        postRouteTraffic:          steps:          - script: echo health check post-route traffic        on:          failure:            steps:            - script: echo Restore from backup! This is on failure          success:            steps:            - script: echo Notify! This is on success这将返回一个错误:/usr/bin/python3: can't find '__main__' module in '/home/ubuntu/azagent/_work/1/test_file.py'##[error]Bash exited with code '1'.如果我将 放置到test_file.py并/home/ubuntu用以下内容替换部署脚本:script: python3 /home/ubuntu/test_file.py该脚本确实运行顺利。如果我将 移动test_file.py到另一个目录,mv /home/ubuntu/azagent/_work/1/test_file.py /home/ubuntu我可以找到一个空文件夹,而不是一个.py文件,名为test_file.py
查看完整描述

1 回答

?
狐的传说

TA贡献1804条经验 获得超3个赞

您无法获取源代码的原因是因为您用于download: current下载当前管道运行产生的工件,但您没有在当前管道中发布任何工件。

由于部署作业不会自动签出源代码,您需要在部署作业中签出源代码,

       - checkout: self

或者在下载之前将源发布到工件。

      - publish: $(Build.SourcesDirectory)
              artifact: Artifact_Deploy


查看完整回答
反对 回复 2023-05-16
  • 1 回答
  • 0 关注
  • 90 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信