skip to Main Content

I was running my pipeline till now on Azure hosted ubuntu pool and my pipeline was running fine. Now I configured self-hosted agents on the Ubuntu server and when running my pipeline it’s failing at the git pull step.

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 

The same pipeline runs fine with Azure-hosted agents(Pool details commented) but fails while runnign on self hosted agent. Any clue what can be missing here.

Here is the error message I get


##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.

2

Answers


  1. Assuming that you have already validated the connectivity from your self-hosted agent instance to ssh.dev.azure.com on port 22 (you can use telnet client and/or Test-TcpConnection for it), it seems that you need to add the Azure DevOps FQDN to the known_hosts file. You can try this command:

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

    Login or Signup to reply.
  2. Please add this task at the very beginning

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

    Or modify you existing install. ssh key step if you have it.

    The value in knownHostsEntry comes from ssh-keyscan -t rsa ssh.dev.azure.com and it will add entry to ~/.ssh/known_hosts

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search