简体   繁体   中英

How to access a private repository from a pipeline Azure Devops?

I have come across this problem that when I queue a build of my flutter code in Azure Pipeline, one of the packages in the pubspec.yaml tries to access a Private Azure repo for one of it's plugin. This is throwing a build error. So how can I solve this in the pipeline.

Thanks in advance.

You can go to the private azure repo, Click Clone and then Click Generate Git Credentials.

在此处输入图片说明

Then you will get a username and password. You can use the username and password to access this private repo. For below example:

git clone https://username:password@dev.azure.com/{org}/{proj}/_git/{repo}

You can also use Personal access token(PAT) with Code read scope to access to private azure repo

git clone https://PAT@dev.azure.com/{org}/{proj}/_git/{repo}

Please check here to get a P erson access token .

Hope above helps!

You can achieve it by using an SSH key with the following steps,

  • Generate an ssh key pair
  • Add a public key to the github repo Upload
  • Private key to the Azure DevOps secure files
  • Configure the Azure DevOps pipeline via YAML

Here is a sample

The question is about Authentication in Build Pipelines, not for cloning the project. Cloning the project is fine whatever mechanism you consider it works. But how does the Build machine that is residing in cloud knows to authenticate?

So I solved this issue by following these steps:

1) create a PAT token for my account in Profile> Security tokens> personal access token

2) define the scopes / permission and copy that PAT token into my local machine (notepad)

3) use the private dependencies in pubspec yaml

Eg:

plugin_name: git: url: https://PAT@dev.azure.com/ {org}/{proj}/_git/{repo}

This workflow is already automated and officially supported. You need to install the official Azure Pipeline in your GitHub account via Marketplace. This will trigger an OAuth authentication workflow to connect your Azure Devops and GitHub account.

After successful authentication you will see a GitHub installation token in your Azure DevOps Service Connections.

After this you will be able to access private repo securely in your pipeline.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM