簡體   English   中英

python 在 Azure 管道的“.py”中找不到“__main__”模塊

[英]python can't find '__main__' module in '.py' in Azure Pipelines

我的目標是通過 Azure 管道將我的 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腳本運行順利。

如果我使用mv /home/ubuntu/azagent/_work/1/test_file.py /home/ubuntutest_file.py移動到另一個目錄,我可以找到一個名為test_file.py的空文件夾,而不是.py文件

編輯

喬布斯截圖:

在此處輸入圖像描述

無法獲取源的原因是因為您使用download: current下載當前管道運行產生的工件,但您沒有在當前管道中發布任何工件。

由於部署作業不會自動簽出源代碼,因此您需要在部署作業中出源代碼,

       - checkout: self

或在下載之前將源發布到工件。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM