Krishna Manohar
Krishna Manohar

Reputation: 334

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.

Upvotes: 3

Views: 8962

Answers (5)

ameya
ameya

Reputation: 1668

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.

enter image description here

Upvotes: 0

Gss Aditya
Gss Aditya

Reputation: 153

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://[email protected]/{org}/{proj}/_git/{repo}

Upvotes: 0

Gss Aditya
Gss Aditya

Reputation: 153

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?

Upvotes: 1

Levi Lu-MSFT
Levi Lu-MSFT

Reputation: 30333

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

enter image description here

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:[email protected]/{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://[email protected]/{org}/{proj}/_git/{repo}

Please check here to get a Person access token.

Hope above helps!

Upvotes: 4

Sajeetharan
Sajeetharan

Reputation: 222592

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

Upvotes: -1

Related Questions