Multiple Repostories in a Pipeline from the same organisation - azure-devops

I got 2 projects within my Azure Organisation. I have created a pipeline from one repository which it's job is to promote code from one repo in the current project to another repo in a different project. I am using YAML and have built up the service connections
# Deploy to PREPROD
resources:
repositories:
- repository: target
type: git
name: 'Other Project/ThisRepo'
trigger:
branches:
include: [
azure-pipelines
]
pool:
name: 'My Pool'
demands:
- agent.computerName -equals MYPC
steps:
- checkout: self
path: source
- checkout: target
path: target
So on the GUI, it shows the target repo and I can browse to it. However when I run the pipeline, I get the following: -
remote: TF401019: The Git repository with name or identifier ThisRepo
does not exist or you do not have permissions for the operation you
are attempting. fatal: repository
'https://dev.azure.com/myOrg/Other%20Project/_git/ThisRepo/' not found
I can't figure out why it can't access it. I've seen in the docs about if I can access it then when the pipeline is created it should be given permission... I don't understand :/
TIA

Please check if your <your project> Build Service accounts belongs to Project Collection Service Accounts on organization level.
I found similar issue solved here
Another option would be to add access only to particular repo to Build Service account from another project:
To do that go to:
Other Project
Settings
Repos -> Repositories
select ThisRepo
select Security tab and type name of the project which wants to use this repo and add Read permission

Related

Azure Devops - Muliple Repos Triggers

Has the Following Feature has been implemented for Gihub Repos yet?strong text
Multi-repo triggers
You can specify multiple repositories in one YAML file and cause a pipeline to trigger by updates to any of the repositories. This feature is useful, for instance, in the following scenarios:
You consume a tool or a library from a different repository. You want to run tests for your application whenever the tool or library is updated.
You keep your YAML file in a separate repository from the application code. You want to trigger the pipeline every time an update is pushed to the application repository.
With this update, multi-repo triggers will only work for Git repositories in Azure Repos. They don't work for GitHub or Bitbucket repository resources.
SAMPLE :
trigger:
main
resources:
repositories:
- repository: tools
type: git
name: MyProject/tools
ref: main
trigger:
branches:
include:
- main
- release
As per Microsoft official sprint 173 updates 2020, this is achiveable using resources tag inside your yaml.
Here is an example that shows how you can setup an auto trigger inside your yaml pipeline based on any change in any other repos inside the same project and even other projects inside Azure DevOps as well.
Sample:
trigger:
- main
resources:
repositories:
- repository: tools
type: git
name: MyProject/tools
ref: main
trigger:
branches:
include:
- main
- release
In the above code snippet:
main branch in the self repo containing the YAML file
main or release branches in tools repo
Here is the link for official documentation form Microsoft for further details.
Hope that solution works for you.
Repository resource triggers only work for Azure Repos Git repositories in the same organization at present. They do not work for GitHub or Bitbucket repository resources.
Refer to this official doc for details: https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/multi-repo-checkout?view=azure-devops#triggers
If you would like this feature to be supported, create a feature request: https://developercommunity.visualstudio.com/AzureDevOps/suggest

Sharing GitHub actions with Enterprise

Overview
The GitHub documentation suggests that actions can be shared between repositories within an enterprise. However, when I try to use an action from inside my enterprise from another repository I get the error:
Error: Unable to clone https://github.com/Org1/action refs/heads/workflow-test: repository not found
Current set up
We have two organizations Org1 and Org2 that are both in the same enterprise. Org1 contains an repository containing an action: Org1/action. Org2 contains a repository which would like to consume this action: Org2/consumer.
I have followed this documentation: https://docs.github.com/en/enterprise-cloud#latest/actions/creating-actions/sharing-actions-and-workflows-with-your-enterprise.
Org1/action
Visibility is set to internal although it was originally private.
I have set Settings>Actions>General>Access to Accessible from repositories in the 'ENTERPRISE NAME' enterprise
Org2/consumer
This repository is set to allow all actions and reusable workflows.
Problem
There is no good documentation on GitHub which explains how to consume actions from within the enterprise.
This is what we currently have in Org2/consumer:
Name: Load test
on: [push]
jobs:
run_action:
runs-on: self-hosted
name: Action
steps:
- name: Trigger Load Test
uses: Org1/action#workflow-test # the action is on this branch
id: action
When we run this action we get the error displayed in the Overview section. This seems like an issue with how the runner is authorizing with GitHub when pulling the repository.
I would love to know if anyone has overcome this issue, or if they have found a work around.
Thanks in advance.

Triggering an Azure pipeline from a repository in a different organization

I'm trying to set up a pipeline that will trigger, when a commit is made in a repository that exists in a different organization.
In my own org, I've created a git repo with a yaml pipeline file in the main branch.
With the below setup, I can checkout the code from the other organization if I run the pipeline manually. But it is not triggered when a commit is pushed to that repository.
Looking at the documentation, this should be possible?
https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/multi-repo-checkout?view=azure-devops#triggers
resources:
repositories:
- repository: OtherOrgRepo # In a different organization
endpoint: OtherOrgConnection
type: git
name: proj/reponame
ref: develop
trigger:
- develop
pool:
vmImage: ubuntu-latest
steps:
- checkout: OtherOrgRepo
The token used for the service connection has full access.
Is this not supported, or am I missing a step?
I guess I just need to read the big blue box:
https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/multi-repo-checkout?view=azure-devops#triggers
Repository resource triggers only work for Azure Repos Git repositories in the same organization at present. They do not work for GitHub or Bitbucket repository resources.
I did however manage to trigger a classic pipeline by using a generic Git service connection, which will poll for changes at an interval.

How can i include folders from other repos when running a pipeline in Azure Devops

I have a repo called REPO A and have created a YAML pipeline in here but I also have some code in REPO B which I need to use in this pipeline
In YAML how can tell the pipeline in REPO A to use files/folders from REPO B?
Im a newbie to this so can you please keep it simple?
resources:
repositories:
- repository: automation
type: git
name: MYORG/ automation
ref: develop
endpoint: YourEndpoint
steps:
- checkout: self
path: "s/Source" : ***>>>>>> what should this be??***
- checkout: automation
You should check out multiple repositories on your YAML pipeline. You can define a new resource repository and checkout this repository along with your source (the one that triggers the pipeline).
resources:
repositories:
- repository: devops_sf
type: github
name: Organization/Repository
ref: master
endpoint: YourEndpoint
steps:
- checkout: self
path: "s/Source"
- checkout: devops_sf
Then you will be able to access your repositories under
$(Pipeline.Workspace)/s/Repository
$(Pipeline.Workspace)/s/Source
Multi repo checkout for Azure DevOps:
https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/multi-repo-checkout?view=azure-devops
ok simply put at the top of the yaml i added
> resources:
> repositories:
> - repository: automation
> type: git
> name: name of yourpoject/name of repo you want to use
> ref: whatever branch of that repo(under repository above) you want to use
THEN!! under steps in the YAML (if you havent one you need to add it!)
> steps:
> - checkout: self
> - checkout: your repository you want to use as above
Also if you use npm to run a task you need to add the below as well to not get any file not found errors! a common error if you dont add the below code is : npm WARN saveError ENOENT: no such file or directory, open '/home/vsts/work/package.json
The below code is put in the -Task section
> > npm install
> > displayName: 'a task using npm'
> > workingDirectory: '$(Build.SourcesDirectory)/your repository you want to use as above
ALSO be aware of indentation when inserting code in YAML it's annoying and a pain if you havent got the indentation right it gives you errors just tab until they go away

Azure YAML Pipelines: How to refer a project and repo in another project in Azure DevOps

I am in an Organization ABC, It has three Azure DevOps projects, namely A, B, and C. Everything is under Azure Repos that means we are not using GitHub.
I am trying to perform a checkout in Project C the repos from project A and B. Every project will have its ow microservices but Shared Platform Services will automate what needs to be deployed into AKS.
Problem Statement: I get error like below when I am trying to checkout repos from projects A and B in Project C. Snippet is as below:
resources:
repositories:
- repository: microservice-a
type: git
name: 'InPlaceCommunications/microservice-a'
ref: master
- repository: microservice-b
type: git
name: 'Project B/microservice-b'
ref: master
However, I get error as below:
remote: TF401019: The Git repository with name or identifier microservice-a does not exist or you do not have permissions for the operation you are attempting.
Any guidance will be very much appreciated.
I do note that I have full permissions to clone the repo myself it is just not happening on the Pipeline.
remote: TF401019: The Git repository with name or identifier microservice-a does not exist or you do not have permissions for the operation you are attempting.
Based on the error message, you need to check the following two points:
Check if the option Limit job authorization scope to current project for non-release pipelines is disable in Project C -> Project Settings -> Settings. You need to disable this option.
Check if the Service Account: Project Collection Build Service (OrganizationName) has the Read Permission in Project A/B -> Project Settings -> Repositories -> Target repos -> Security.