为什么我在触发构建管道时出现错误?在默认池中找不到满足指定要求的代理?

问题描述 投票:0回答:2

我正在 Azure DevOps CICD 管道中工作。我在默认池中创建了一个代理,它是一个自托管代理。

我的代理详细信息:

代理.名称:部署代理 代理版本:2.210.1

下面是我的yaml文件:

trigger: none

variables:
- name: solution
  value: 'MyApp.sln'
- name: buildPlatform
  value: 'Any CPU'
- name: buildConfiguration
  value: 'Release'
- name: "npm_config_cache"
  value: $(Pipeline.Workspace)/.npm

stages:
- stage: StartAzVMAgent
  jobs:
  - job: MsHostedAgentJobStartAzVM
    timeoutInMinutes: 0
    pool:
      vmImage: 'windows-latest'
    steps:
    - task: AzureCLI@2
      displayName: Azure CLI
      inputs:
        azureSubscription: "Az-DevOps-AgentManager"
        scriptType: ps
        scriptLocation: inlineScript
        inlineScript: |
          az --version
          az account show
          az vm start --name  MyDeployment-Agent --no-wait --resource-group MyDeployment

- stage: __default
  jobs:
  - job: Job
    timeoutInMinutes: 0
    pool:
      name: Default
      demands:
      - Agent.Name -equals Deployment-Agent
    steps:
     - task: Npm@1
       displayName: Install Node dependencies (packages)
       inputs:
         command: custom
         customCommand: install --save --legacy-peer-deps 
         workingDir: 'MyApp.WebUI\MyClientApp'
        
     - task: Npm@1
       displayName: Install Node dependencies (packages)
       inputs:
         command: custom
         customCommand: install sweetalert2 file-saver 
         workingDir: 'MyApp.WebUI\MyClientApp'
         
    - task: Cache@2
      displayName: Cache npm
      inputs:
        key: 'npm | "$(Agent.OS)" | **/package-lock.json'
        restoreKeys: |
          npm | "$(Agent.OS)"
        path: $(npm_config_cache)
    - script: npm ci

    - task: CmdLine@2
      displayName: Building Client App
      inputs:
        script: node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build  --configuration production --aot --build-optimizer=true --common-chunk=true  --named-chunks=false --optimization=true --vendor-chunk=true --progress=true
        workingDirectory: 'MyApp.WebUI\MyClientApp'
        
    - task: CopyFiles@2
      displayName: 'Copy Client Project'
      inputs:
        Contents: |
          MyApp.WebUI\MyClientApp\dist\**
        TargetFolder: '$(build.artifactstagingdirectory)/client'
        flattenFolders: false
        CleanTargetFolder: true
        
    - task: UseDotNet@2
      displayName: Use .NET 6.0
      inputs:
          packageType: 'sdk'
          version: '6.0.x'
          installationPath: $(Agent.ToolsDirectory)/dotnet
          
    - task: DotNetCoreCLI@2
      inputs:
        command: 'publish'
        publishWebProjects: true
        zipAfterPublish: true
        arguments: '--output $(build.artifactstagingdirectory)/api'

    - task: CmdLine@2
      displayName: Create EF Scripts
      inputs:
        script: |
          dotnet ef migrations add  FreshDb_08022021  -c MyAppDbcontext
          dotnet ef migrations script   --idempotent  --output migrations.sql --project MyApp.Persistence/MyApp.Persistence.csproj --context MyAppDbContext
   
   - task: CopyFiles@2
      displayName: 'Copy EF Scripts to Staging'
      inputs:
        Contents: "**\\migrations.sql \n"
        TargetFolder: '$(build.artifactstagingdirectory)'
        flattenFolders: true
  
    - task: PublishBuildArtifacts@1
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)'
        ArtifactName: 'drop'
        publishLocation: 'Container'

- stage: StoptAzVMAgent
  dependsOn: __default
  condition: always()
  jobs:
  - job: MsHostedAgentJobStopAZVm
    timeoutInMinutes: 0
    pool:
      vmImage: 'windows-latest'
    steps:
    - task: AzureCLI@2
      displayName: Azure CLI
      inputs:
        azureSubscription: "Az-DevOps-AgentManager"
        scriptType: ps
        scriptLocation: inlineScript
        inlineScript: |
          az --version
          az account show
          az vm deallocate --name MyDeployment-Agent --no-wait --resource-group MyDeployment

但是,即使我的代理已启用并运行,我也会收到以下错误。

#Error: 在默认池中找不到满足指定要求的代理:Use_for -equals Deployment-Agent, npm, Agent.Version -gtVersion 2.182.1

我可以知道它是否采用 2.182.1 作为版本,因为我的代理版本高于此版本,但仍然采用以前的版本并给我错误?由于我是 azure CICD 的新手,有人可以帮我吗?

azure-devops yaml continuous-integration azure-pipelines-yaml azure-devops-self-hosted-agent
2个回答
1
投票

根据错误信息,请尝试以下步骤:

  1. 检查代理中“Use_for”的用户能力。
  2. 在代理中安装 NPM,然后重新启动代理以扫描 NPM。

更多信息,您可以参考:https://learn.microsoft.com/en-us/azure/devops/pipelines/process/demands?view=azure-devops&tabs=yaml

并安装 NPM:https://docs.npmjs.com/downloading-and-installing-node-js-and-npm


0
投票

添加第一个任务:

  - task: NodeTool@0
    displayName: Installing Node.JS  
    inputs:
      versionSpec: '16.x'
© www.soinside.com 2019 - 2024. All rights reserved.