【问题标题】:Azure pipeline defaults to wrong agentAzure 管道默认使用错误的代理
【发布时间】:2021-08-09 09:59:40
【问题描述】:

我有以下问题:我指定了一个管道 yaml,它在第一阶段的自托管代理上运行。对于第二阶段,我还没有宣布代理。它应该默认为 Microsoft 托管的代理(并且适用于具有相同语法和用例的所有其他管道)。但是,在执行时初始化代理时,所选代理属于自托管种类。 我尝试创建一个 fork,删除 repo 并重新初始化它。两者都无济于事。 当我为舞台指定代理时,就像这样(如本 ms documentation 中所述):

pool:
  vmImage: 'ubuntu-latest'

我收到以下消息: There was a resource authorization issue: "The pipeline is not valid. Could not find a pool with name Azure Pipelines. The pool does not exist or has not been authorized for use. For authorization details, refer to https://aka.ms/yamlauthz." 当我单击授权资源时,我会收到成功的消息。但是,授权问题不断出现。

azure-pipeline.yaml

resources:
  repositories:
    - repository: templates
      type: git
      name: azure-devops-reusable-tasks

variables:
  - group: mijnverzekeringsvoorwaarden-api-service_ONT # for deployments (build scripts only target ONT)
  - template: add-variable-branch-name.yml@templates

name: 1.0.0$(branchName)-$(Build.BuildId)

stages:
  - stage: Build
    displayName: Build
    jobs:
      - job: Build
        displayName: Build
        pool:
          name: Default
          demands: companyName.Docker
        steps:
          - template: maven.yml@templates
          - publish: $(System.DefaultWorkingDirectory)
            artifact: mijnverzekeringsvoorwaarden-api-service
          - template: publish-surefire-test-results.yml@templates
          - template: publish-jacoco-code-coverage.yml@templates
          - template: git-set-version-tag.yml@templates

  - stage: Scan
    dependsOn: Build
    jobs:
      - job: Scan
        displayName: Dependency scan
        steps:
          - template: owasp-scan.yml@templates

这是第二阶段调用的有问题的模板。应该在 MS 托管的机器上运行的那个:

owasp-scan.yml@templates

steps:
  - download: current
  - task: dependency-check-build-task@6
    displayName: Owasp dependency check
    inputs:
        projectName: $(Build.Repository.Name)
        scanPath: $(Pipeline.Workspace)
        format: 'HTML'

任何关于为什么它默认为这个特定管道的错误池的任何见解?

更新: 添加了 microsoft 托管池中的代理池和代理的屏幕截图。 尝试使用屏幕截图中给出的名称引用代理池,如下所示:

pool:
  name: 'Hosted Ubuntu 1604'
  vmImage: 'ubuntu-latest'

这会产生以下错误: ##[error]No agent found in pool Hosted Ubuntu 1604 which satisfies the following demand: ubuntu-latest. All demands: ubuntu-latest, Agent.Version -gtVersion 2.188.2

使用时:

pool:
  name: 'Hosted Ubuntu 1604'
  vmImage: 'Hosted Ubuntu 1604 2'

我得到: Encountered error(s) while parsing pipeline YAML: /azure-pipelines.yml (Line: 37, Col: 20): Invalid demand 'Hosted Ubuntu 1604 2'. The demand should be in the format '<NAME>' to test existence, and '<NAME> -equals <VALUE>' to test for a specific value. For example, 'VISUALSTUDIO' or 'agent.os -equals Windows_NT'.

更新 2: 我比较了项目。另一个项目确实有 Azure Pipelines 代理池。我批准了这个项目(有问题的那个)也可以访问这个池。当我在 yaml 中明确定义它时,它使用这个(云托管)池。但是,当我没有提供池信息时,它会一直默认为自托管变体。重复一遍,这只发生在这个特定的管道上。

【问题讨论】:

  • 您好,您可以显示代理池的屏幕截图吗?
  • 如何将name: Default 更改为name: Azure Pipelines
  • 该池 Azure Pipelines 不存在。见截图。
  • 该池确实存在于同一组织内的其他项目中。有关更多信息,请参阅更新 2 @1_1

标签: azure-devops azure-pipelines


【解决方案1】:

任何关于为什么它默认为这个特定管道的错误池的任何见解?

您可以尝试在 UI 中将 YAML 的默认代理池中的值更改为 Azure Pipelines

【讨论】:

  • @MyName,奇怪。你的意思是没有托管代理?如果是,请您使用有关它的图像和有关项目设置->代理池->Azure 管道->代理的图像更新您的问题。
  • 据我所知,托管的 Ubuntu 是云托管的。它旁边甚至还有一个云的符号(我没有放在那里)。这是所有的游泳池。在运行任何其他管道时,未定义池,它会在运行时检索 Microsoft 托管机器。
  • @MyName,这和我们展示的不一样。请尝试使用pool: name: 'Hosted Ubuntu 1604' 而不使用vmImage: 'Hosted Ubuntu 1604 2'。我们无法直接指定代理。如果你想指定一个socify代理,你需要使用需求
  • @MyName,如果在 YAML 管道中不指定代理池,它将使用默认代理 Hosted Ubuntu 1604
  • 是的。在这种特定情况下,它会失败,它会从我们的自托管池中获取一个代理。我已将选项切换为 azure pipelines。它现在按预期工作。即使没有定义代理池。
【解决方案2】:

问题已被规避。当从代理池中明确定义代理时,使用正确的命名法,它会从该池中选择一个代理。 然而,这并不能解释为什么这个管道会出现这种行为,而所有其他管道从同一个池中选择一个代理而不定义它。这些默认为这个(相同的)池。

在这种特定情况下,hack 是这样定义池的:

pool:
  name: 'Hosted Ubuntu 1604'

【讨论】:

    猜你喜欢
    • 2019-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多