Yaml 将Azure管道部署迁移到GitHub操作

Yaml 将Azure管道部署迁移到GitHub操作,yaml,azure-pipelines,azure-pipelines-release-pipeline,github-actions,Yaml,Azure Pipelines,Azure Pipelines Release Pipeline,Github Actions,我有一个Azure管道构建,它在Windows、MacOS和Linux上构建NuGet软件包,还有一个部署作业,它将从Windows映像构建的NuGet软件包发布到Azure Artefacts、GitHub软件包和NuGet 通过GitHub操作,我已经成功地在Windows、MacOS和Linux上构建了NuGet软件包,但我不知道如何创建部署作业,因为该功能不存在。我认为我需要创建一个新的部署作业,该作业由成功的构建作业触发,从成功的构建中获取NuGet包,然后推送它们。然而,我没有看到一

我有一个Azure管道构建,它在Windows、MacOS和Linux上构建NuGet软件包,还有一个部署作业,它将从Windows映像构建的NuGet软件包发布到Azure Artefacts、GitHub软件包和NuGet

通过GitHub操作,我已经成功地在Windows、MacOS和Linux上构建了NuGet软件包,但我不知道如何创建部署作业,因为该功能不存在。我认为我需要创建一个新的部署作业,该作业由成功的构建作业触发,从成功的构建中获取NuGet包,然后推送它们。然而,我没有看到一个触发器类型可以做到这一点

GitHub操作构建YAML Azure管道构建和部署YAML 将Azure管道部署迁移到GitHub操作

事实上,目前Github操作还没有这样的多阶段特性

正如您所怀疑的,我们可以创建一个部署作业来部署工件。我们可以尝试创建一个需要现有构建作业的新作业,在新作业中,下载工件并将其推送到azure工件、github包、nuget:

jobs:
  job_1:
    name: Build

  job_2:
    name: Deploy
    needs: job_1
    runs-on: windows-latest
    steps:
      - name: Download math result for job 1
      uses: actions/download-artifact@v1
      with:
        name: xxx
您可以查看Github操作并了解更多详细信息

希望这有帮助

trigger:
  branches:
    include:
    - '*'
  tags:
    include:
    - '*'
variables:
  DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
  DOTNET_CLI_TELEMETRY_OPTOUT: true
  MINVERBUILDMETADATA: build.$(Build.BuildId)
stages:
- stage: Build
  jobs:
  - job: Build
    strategy:
      matrix:
        Linux:
          matrixName: Ubuntu
          vmImageName: ubuntu-latest
        Mac:
          matrixName: Mac
          vmImageName: macos-latest
        Windows:
          matrixName: Windows
          vmImageName: windows-latest
    pool:
      vmImage: $(vmImageName)
    timeoutInMinutes: 10
    steps:
    - checkout: self
      lfs: true
    - task: UseDotNet@2
      displayName: 'Install .NET Core SDK'
      inputs:
        packageType: 'sdk'
        useGlobalJson: true
    - pwsh: 'dotnet tool restore'
      displayName: 'Dotnet Tool Restore'
      failOnStderr: true
    - pwsh: 'dotnet cake --target=Build'
      displayName: 'Dotnet Cake Build'
      failOnStderr: true
    - pwsh: 'dotnet cake --target=Test'
      displayName: 'Dotnet Cake Test'
      failOnStderr: true
    - pwsh: 'dotnet cake --target=Pack'
      displayName: 'Dotnet Cake Pack'
      failOnStderr: true
    - task: PublishTestResults@2
      displayName: 'Publish Test Results'
      inputs:
        testResultsFormat: 'VSTest'
        testResultsFiles: '**/*.trx'
    - task: PublishCodeCoverageResults@1
      inputs:
        codeCoverageTool: cobertura
        summaryFileLocation: '**/*.cobertura.xml'
    - publish: './Artefacts'
      artifact: $(matrixName)
      displayName: 'Publish Artefacts'
- stage: Deploy
  jobs:
  - deployment: AzureArtefacts
    displayName: 'Azure Artefacts'
    condition: ne(variables['Build.Reason'], 'PullRequest')
    pool:
      vmImage: windows-latest
    environment: 'Azure Artefacts'
    strategy:
      runOnce:
        deploy:
          steps:
          - task: NuGetToolInstaller@1
            displayName: 'NuGet Install'
          - task: NuGetAuthenticate@0
            displayName: 'NuGet Authenticate'
          - pwsh: nuget push $(Agent.BuildDirectory)\Windows\*.nupkg -Source $(AzureArtefactsSource) -ApiKey AzureArtifacts -SkipDuplicate
            displayName: 'NuGet Push'
            failOnStderr: true
  - deployment: GitHub
    condition: ne(variables['Build.Reason'], 'PullRequest')
    pool:
      vmImage: windows-latest
    environment: 'GitHub'
    strategy:
      runOnce:
        deploy:
          steps:
          - task: NuGetToolInstaller@1
            displayName: 'NuGet Install'
          - pwsh: nuget source Add -Name GitHub -Source https://nuget.pkg.github.com/GITHUB-USERNAME -UserName GITHUB-USERNAME -Password $(GitHubPersonalAccessToken)
            displayName: 'NuGet Add Source'
            failOnStderr: true
          - pwsh: nuget push $(Agent.BuildDirectory)\Windows\*.nupkg -Source GitHub -SkipDuplicate
            displayName: 'NuGet Push'
            failOnStderr: true
  - deployment: NuGet
    condition: and(ne(variables['Build.Reason'], 'PullRequest'), startsWith(variables['Build.sourceBranch'], 'refs/tags/'))
    pool:
      vmImage: windows-latest
    environment: 'NuGet'
    strategy:
      runOnce:
        deploy:
          steps:
          - task: NuGetToolInstaller@1
            displayName: 'Install NuGet'
          - pwsh: |
              Get-ChildItem $(Agent.BuildDirectory)\Windows -Filter *.nupkg |
              Where-Object { !$_.Name.Contains('preview') } |
              ForEach-Object { nuget push $_ -Source https://api.nuget.org/v3/index.json -ApiKey $(NuGetApiKey) -SkipDuplicate }
            displayName: 'NuGet Push'
            failOnStderr: true
jobs:
  job_1:
    name: Build

  job_2:
    name: Deploy
    needs: job_1
    runs-on: windows-latest
    steps:
      - name: Download math result for job 1
      uses: actions/download-artifact@v1
      with:
        name: xxx