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
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
Please add this task at the very beginning
Or modify you existing install. ssh key step if you have it.
The value in
knownHostsEntry
comes fromssh-keyscan -t rsa ssh.dev.azure.com
and it will add entry to~/.ssh/known_hosts