Found a solution to use private repo
After the SSH key pair generated, add the SSH public key to the User settings > SSH Public Keys page on your Azure DevOps. See
Attempt cloning your Git repository via SSH on your local machine to ensure the SSH can work as expected.
Upload the SSH private key to Secure files in the project on Azure DevOps.
In Azure Pipelines, you can use the Install SSH Key task to download the SSH private key from the Secure files and install it on the agent. After successfully installing the SSH private key, on the subsequent tasks in the same job you can use the SSH to clone the Git repository (for example, git clone [email protected]:v3/{organization}/{project}/{repositoryName}
).
Below is a sample of the YAML pipeline as reference:
jobs:
- job: build
displayName: 'Build'
pool:
vmImage: windows-latest
steps:
. . .
- task: InstallSSHKey@0
displayName: 'Install SSH Private Key'
inputs:
knownHostsEntry: '$(SSHknownHost)' // The value is the content of 'known_hosts' file.
sshKeySecureFile: 'id_rsa'
- task: Bash@3
displayName: 'Clone Repository'
inputs:
targetType: inline
script: |
echo 'Clone Repository via SSH'
git clone [email protected]:v3/{organization}/{project}/{repositoryName}
. . .