Home > Software engineering >  Azure build pipeline with dependency on private AZ repo with SSH
Azure build pipeline with dependency on private AZ repo with SSH

Time:11-24

Found a solution to use private repo enter image description here

  • After the SSH key pair generated, add the SSH public key to the User settings > SSH Public Keys page on your Azure DevOps. See enter image description here

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

    enter image description here

  • 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}
    
      . . .
    
    • Related