0

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

有一个例子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'
4

1 回答 1

0

在 Azure DevOps 中创建新管道时,首先选择GitHub源代码的位置,从而完成向导的步骤。您可能会被重定向到 GitHub 进行登录。如果是这样,请输入您的 GitHub 凭据。出现存储库列表时,选择您的存储库。你可能会被重定向到 GitHub 以安装 Azure Pipelines 应用。如果是这样,请选择批准并安装。然后在构建期间,repo 将被下载到$(Agent.BuildDirectory).

在此处输入图像描述

要在存储库中运行 Python 脚本,请使用script元素并指定文件名。例如:

- script: python src/example.py

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

于 2020-07-10T09:11:01.490 回答