python 在 Azure Pipelines 的“.py”中找不到“__main__”模块
python can't find '__main__' module in '.py' in Azure Pipelines
我的目标是通过 Azure Pipeline 从 GitHub 部署 运行 我的 python 脚本到我的虚拟机。我的 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
这returns一个错误:
/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
编辑
来自乔布斯的截图:
您无法获取源码的原因是因为您使用了当前管道运行生产的download: current
到download artifacts,但您没有在当前管道中发布任何工件管道。
由于部署作业不会自动检出源代码,您需要 checkout 部署作业中的源代码,
- checkout: self
或publish 下载前工件的来源。
- publish: $(Build.SourcesDirectory)
artifact: Artifact_Deploy
我的目标是通过 Azure Pipeline 从 GitHub 部署 运行 我的 python 脚本到我的虚拟机。我的 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
这returns一个错误:
/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
编辑
来自乔布斯的截图:
您无法获取源码的原因是因为您使用了当前管道运行生产的download: current
到download artifacts,但您没有在当前管道中发布任何工件管道。
由于部署作业不会自动检出源代码,您需要 checkout 部署作业中的源代码,
- checkout: self
或publish 下载前工件的来源。
- publish: $(Build.SourcesDirectory)
artifact: Artifact_Deploy