通过Azure Pipeline将Python脚本从GitHub部署到虚拟机

时间:2020-07-09 14:32:45

标签: azure github azure-devops azure-pipelines azure-pipelines-yaml

我的目标是通过Azure Pipeline将python脚本从GitHub部署到我的虚拟机。我已经建立了连接,但是我不知道如何将GitHub存储库克隆到虚拟机。我已按照here

的说明进行操作

有一个示例azure-pipeline.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
                artifact: drop
              - script: echo initialize, cleanup, backup, install certs
            deploy:
              steps:
              - task: Bash@3
                inputs:
                  targetType: 'inline'
                  script: |
                    # Modify deployment script based on the app type
                    echo "Starting deployment script run"
                    sudo java -jar '$(Pipeline.Workspace)/drop/**/target/*.jar'
            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

我应该在部署部分放置什么才能使部署工作?我想将脚本从GitHub克隆到特定文件夹并立即启动。我认为这是我需要修改的全部内容:

# Modify deployment script based on the app type
  echo "Starting deployment script run"
  sudo java -jar '$(Pipeline.Workspace)/drop/**/target/*.jar'

1 个答案:

答案 0 :(得分:0)

在Azure DevOps中创建新管道时,请首先选择cloudpickle作为源代码的位置,以逐步完成向导的步骤。您可能会重定向到GitHub进行登录。如果是,请输入GitHub凭据。当存储库列表出现时,选择您的存储库。您可能会重定向到GitHub以安装Azure Pipelines应用程序。如果是这样,请选择批准并安装。然后,在构建过程中,存储库将下载到GitHub

enter image description here

要在存储库中运行Python脚本,请使用$(Agent.BuildDirectory)元素并指定文件名。例如:

script

更多详细信息,您可以参考以下文档: https://docs.microsoft.com/en-us/azure/devops/pipelines/ecosystems/python?view=azure-devops