具有自托管代理的 Azure DevOps 管道在 git checkout 步骤失败,而在 Azure 托管代理上同样有效

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

到目前为止,我一直在 Azure 托管的 ubuntu 池上运行管道,并且管道运行良好。现在我在 Ubuntu 服务器上配置了自托管代理,当运行我的管道时,它在 git pull 步骤失败。

trigger:
  batch: true
  branches:
    include:
    - main
  paths:
    include:
    - rg-test-cmn-syd-01-bastion

#pool:
  #vmImage: ubuntu-latest

pool:
  name: self-hosted
  demands:
   - agent.name -equals devops-agent-01   

variables:
  environmentName: 'dev'
  resource_group: '******'
  workDirectory: 'myworkdir'
  gitRepository: 'ssh://[email protected]/v3/myorg/myproject'
  backendType: 'azurerm'
  backendServiceArm: '***'
  backendAzureRmSubscriptionId: '*******'
  backendAzureRmResourceGroupName: '******'
  backendAzureRmStorageAccountName: '*****'
  backendAzureRmContainerName: '*****'
  backendAzureRmKey: '$(resource_group).tfstate'
  environmentServiceName: '*****'
 

stages :
  - stage: terraform_plan
    jobs:
      - job: terraform_plan
        displayName: "Terraform Plan"
        steps:
          - checkout: none

          - task: InstallSSHKey@0
            inputs:
              knownHostsEntry: $(known_host)
              sshPublicKey: '******'
              sshKeySecureFile: 'testkey'
              
          - task: CmdLine@2
            displayName: 'Git pull $(workDirectory)'
            inputs:
              script: |
                echo [command] git init
                git init
                echo [command] git sparse-checkout: $(workDirectory)
                git config core.sparsecheckout true
                echo $(workDirectory) >> .git/info/sparse-checkout
                echo [command] git remote add $(gitRepository)
                git remote add origin $(gitRepository)
                echo ##[command] git fetch --progress --verbose --depth=1 origin main
                git fetch --progress --verbose --depth=1 origin main
                ##echo ##[command] git pull --progress --verbose origin main
                git pull --progress --verbose origin main 

同一管道在 Azure 托管代理上运行良好(池详细信息已注释),但在自托管代理上运行时失败。这里可能缺少什么线索。

这是我收到的错误消息


##git pull --progress --verbose origin main
##[debug]workingDirectory=/myagent/_work/2/s
##[debug]check path : /myagent/_work/2/s
Generating script.
##[debug]Agent.Version=3.220.5
##[debug]agent.tempDirectory=/myagent/_work/_temp
##[debug]check path : /myagent/_work/_temp
========================== Starting Command Output ===========================
##[debug]which 'bash'
##[debug]found: '/usr/bin/bash'
##[debug]which '/usr/bin/bash'
##[debug]found: '/usr/bin/bash'
##[debug]/usr/bin/bash arg: --noprofile
##[debug]/usr/bin/bash arg: --norc
##[debug]/usr/bin/bash arg: /myagent/_work/_temp/229ea54f-8b84-413a-915a-5c29dab2b0fc.sh
##[debug]exec tool: /usr/bin/bash
##[debug]arguments:
##[debug]   --noprofile
##[debug]   --norc
##[debug]   /myagent/_work/_temp/229ea54f-8b84-413a-915a-5c29dab2b0fc.sh
/usr/bin/bash --noprofile --norc /myagent/_work/_temp/229ea54f-8b84-413a-915a-5c29dab2b0fc.sh
 git init
Reinitialized existing Git repository in /myagent/_work/2/s/.git/
 git sparse-checkout: TESRT-Infra/common/rgname/
 git remote add ssh://[email protected]/v3/***/***/***
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

git azure azure-devops ubuntu-18.04 azure-pipelines-yaml
2个回答
0
投票

假设您已经验证了从自托管代理实例到端口 22 上的 ssh.dev.azure.com 的连接(您可以使用 telnet 客户端和/或 Test-TcpConnection),似乎您需要添加Azure DevOps FQDN 到known_hosts 文件。你可以尝试这个命令:

ssh-keyscan -t rsa ssh.dev.azure.com >> ~/.ssh/known_hosts


0
投票

请在开头添加此任务

- task: InstallSSHKey@0
  inputs:
    knownHostsEntry: "ssh.dev.azure.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7Hr1oTWqNqOlzGJOfGJ4NakVyIzf1rXYd4d7wo6jBlkLvCA4odBlL0mDUyZ0/QUfTTqeu+tm22gOsv+VrVTMk6vwRU75gY/y9ut5Mb3bR5BV58dKXyq9A9UeB5Cakehn5Zgm6x1mKoVyf+FFn26iYqXJRgzIZZcZ5V6hrE0Qg39kZm4az48o0AUbf6Sp4SLdvnuMa2sVNwHBboS7EJkm57XQPVU3/QpyNLHbWDdzwtrlS+ez30S3AdYhLKEOxAG8weOnyrtLJAUen9mTkol8oII1edf7mWWbWVf0nBmly21+nZcmCTISQBtdcyPaEno7fFQMDD26/s0lfKob4Kw8H"

或者修改您现有的安装。 ssh 关键步骤(如果有的话)。

knownHostsEntry
中的值来自
ssh-keyscan -t rsa ssh.dev.azure.com
,它将向
~/.ssh/known_hosts

添加条目
© www.soinside.com 2019 - 2024. All rights reserved.