How to git diff on an Azure DevOps CI pipeline with more than one repository

There are a few helpful [questions and answers][1] online,

[1]: How to git diff on a Azure CI pipeline, but they seem to be working in a single-repository environment. I’m using one git repository for the project source, another for a department-wide YAML code repo that covers several projects.

My current challenge is getting a list of changed files as a result of a PullRequest, IndividualCI, or BatchCI Build.Reason for the product repo. The list is needed for a CI static code analysis.

Using git diff --name-only HEAD^ HEAD (or HEAD~ HEAD or @~ @) all give me fatal: not a git repository (or any of the parent directories): .git

With two repositories, the Build.SourceDirectory gets the name of the repositories appended, but I haven’t been able to find for to use that information (e.g. agent_work1sfoo) in or before the git diff call.

Has anyone come across that problem, or any suggestions for a solution?

Assuming you have defined additional repository resource(s) in your YAML pipeline to be consumed together with the self repo, and according to the document,

Unless a path is specified in the checkout step, source code is placed in a default directory. This directory is different depending on whether you are checking out a single repository or multiple repositories.

Multiple repositories: If you have multiple checkout steps in your job, your source code is checked out into directories named after the repositories as a subfolder of s in (Agent.BuildDirectory). If (Agent.BuildDirectory) is C:agent_work1 and your repositories are named tools and code, your code is checked out to C:agent_work1stools and C:agent_work1scode,

Therefore, you may try the sample YAML pipeline below to run git diff in different repo paths on that agent machine.

resources:
 repositories:
   - repository: RepoA
     name: RepoA
     type: git

variables:
  RepoA.name: $[ resources.repositories.RepoA.name ]
  RepoA.ref: $[ resources.repositories.RepoA.ref ]
  RepoA.version: $[ resources.repositories.RepoA.version ]

steps:
# Set fetchDepth as 0 to disable the dault shallow fetch 1
- checkout: self
  fetchDepth: 0
- checkout: RepoA
  fetchDepth: 0
- script: |
    echo "================ 1. Show file structure in Pipeline.Workspace ================"
    tree $(Pipeline.Workspace)
    
    echo "================ 2. Show self repo info and run git diff ================"
    cd $(Agent.BuildDirectory)/s/$(Build.Repository.Name)
    echo "self repo name: $(Build.Repository.Name)"
    echo "self repo ref: $(Build.SourceBranch)"
    echo "self repo commit version: $(Build.SourceVersion)"
    git diff --name-only $(Build.SourceVersion)^ $(Build.SourceVersion)
    
    echo "================ 3. Show $(RepoA.name) info and run git diff ================"
    cd $(Agent.BuildDirectory)/s/$(RepoA.name)
    echo "RepoA name: $(RepoA.name)"
    echo "RepoA ref: $(RepoA.ref)"
    echo "RepoA commit version: $(RepoA.version)"
    git diff --name-only $(RepoA.version)^ $(RepoA.version)
  displayName: Run git diff in multiple repo paths

9

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật