【问题标题】:in Azure DevOps, where are the stages of a pipeline actually run?在 Azure DevOps 中,管道的各个阶段实际运行在哪里?
【发布时间】:2022-02-10 04:31:44
【问题描述】:

我从使用 Jenkins 的经验来到 Azure DevOps,很明显,正在运行的管道中的代码实际上是在 Jenkins 服务器上运行的(无论托管该服务器的机器是什么)。所以我假设 Azure DevOps 管道在 https://dev.azure.com/ 的某个地方运行。也许这是真的,也许不是。也许这取决于“环境”的设置方式以及该环境中的资源。我的多阶段管道如下所示:

# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4

trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'



stages: 
- stage: build
  displayName: Build
  jobs:
  - job: Build


    steps:

    - checkout: self


    #without this first one, bad things happen!!
    - task: NuGetCommand@2
      inputs:
        command: 'restore'
        restoreSolution: '**/*.sln'
        feedsToUse: 'config'
        nugetConfigPath: 'NuGet.config'
        
    - task: NuGetToolInstaller@1


    - task: VSBuild@1
      inputs:
        solution: '$(solution)'
        msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
        platform: '$(buildPlatform)'
        configuration: '$(buildConfiguration)'

    - task: VSTest@2
      inputs:
        platform: '$(buildPlatform)'
        configuration: '$(buildConfiguration)'

    - task: PublishBuildArtifacts@1
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)'
        ArtifactName: 'drop'
        publishLocation: 'Container'


- stage: Release
  displayName: Release
  condition: and(succeeded(), eq(variables['build.sourceBranch'], 'refs/heads/master'))
  jobs:

  - deployment:
    displayName: Release
    environment: 
        name: QA
        resourceType: VirtualMachine
    strategy:
      runOnce:
        deploy:
          steps:
          - task: CopyFiles@2
            inputs:  
              SourceFolder: '$(Agent.WorkFolder)\1\drop'
              Contents: '**\*.zip'
              OverWrite: true
              TargetFolder: 'C:\QA\XXX\YYY'

我知道“C:\QA\XXX\YYY”在我要部署到的服务器上(QA Azure DevOps 环境中的一个资源)。但这些地点在哪里?

$(Build.ArtifactStagingDirectory)

$(Agent.WorkFolder)

其中一些路径中有“D:”,但在我要部署到的服务器上却没有 D:。 Microsoft 的文档似乎从来没有真正解决过这个问题,但理解它对于任何试图跟上 Azure DevOps 速度的人来说似乎都是必不可少的。

【问题讨论】:

    标签: azure-devops yaml continuous-deployment


    【解决方案1】:

    管道在agent 上运行,可以位于以下两个位置之一:

    Microsoft-Hosted Agents 每个都在 Microsoft 新创建的单一用途 VM 上运行,并在单个管道作业完成后销毁。

    Self-Hosted Agents 由您在您的基础架构上(本地或云端)运行。他们坚持并运行多个作业是正常的。你可以运行它们:

    • 在本地物理服务器上
    • 在 Azure VM 上
    • 在 Azure VMSS 上

    无论您使用哪种代理,这些预定义变量($(Build.ArtifactStagingDirectory)$(Agent.WorkFolder))对应于本地文件位置运行代理的服务器。

    您选择“windows-latest”池意味着您的管道在 Microsoft 托管的代理、Windows VM 上运行。

    【讨论】:

    • 我希望微软自己能在某处提供这些信息。谢谢!
    【解决方案2】:
    pool:
       vmImage: 'windows-latest'
    

    这是您指定的作业应该在哪里运行的池。

    您的部署作业正在使用runOnce 策略,它告诉它在windows-latest 代理池上运行该部署作业一次。如果要在环境中跨机器运行作业,则需要使用适当的deployment strategy,例如rollingcanary

    【讨论】:

    • 明确一点,代理池在哪里?它是以某种方式在我的目标资源上,还是微软为 Azure DevOps 提供的虚拟服务器?我可以远程桌面进入吗?我可以浏览它的目录吗?除了在我的管道中运行任务之外,它还能为我提供什么(如果有的话)?
    • 我突然收到错误的原因可能是“找不到 .NETFramework,Version=v4.6.1 的参考程序集”。 -- 这是否意味着微软更新了 windows-latest 以删除该框架?
    • 如果您使用的是 Microsoft 托管的代理池,那么所有问题的答案都是“否”。将其视为 Microsoft 控制的管道的临时、一次性工作区。如果您愿意,您也可以设置自己的自托管代理并将它们添加到单独的代理池中。
    • 有趣的是,我发现当我将 vmImage 从“windows-latest”更改为“windows-2019”时,“找不到 .NETFramework,Version=v4.6.1 的参考程序集。”错误消失了,确认构建环境位于该 vmImage 上,并且在 2022 年 2 月 8 日或前后,微软必须将 windows-latest 更改为 windows-2022(它曾是 windows-2019)或删除 .NETFramework,Version =v4.6.1 来自 windows 最新版本。感谢您帮助我找到答案,Daniel!
    • @DanielMann 您的回答并没有真正回答 OP 的问题。但是,您的评论非常有用。
    猜你喜欢
    • 2021-03-25
    • 1970-01-01
    • 2021-03-18
    • 2022-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-15
    • 2020-10-31
    相关资源
    最近更新 更多