Permission scope in azure repos api usage in azure devops pipeline

I am using azure api call to list down all repositories under one organization: https://learn.microsoft.com/en-us/rest/api/azure/devops/git/repositories/list?view=azure-devops-rest-7.1&tabs=HTTP

And I use this specific endpoint:
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories?api-version=7.1-preview.1

But when I try to use this endpoint via shell script in the pipeline, it only lists down exactly one, the parent repository where the script is being written on instead of all repositories in the project.

Here is my code so far

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> steps:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
$header = @{ Authorization = "Bearer $(System.AccessToken)" }
$allReposUrl = "$($env:SYSTEM_TEAMFOUNDATIONSERVERURI)_apis/git/repositories?api-version=6.0"
$allReposResponse = (Invoke-RestMethod -Uri $allReposUrl -Method Get -Headers $header).value
$allReposResponse | ForEach-Object {
echo "LOG: $($_)"
}
</code>
<code> steps: - task: PowerShell@2 inputs: targetType: 'inline' script: | $header = @{ Authorization = "Bearer $(System.AccessToken)" } $allReposUrl = "$($env:SYSTEM_TEAMFOUNDATIONSERVERURI)_apis/git/repositories?api-version=6.0" $allReposResponse = (Invoke-RestMethod -Uri $allReposUrl -Method Get -Headers $header).value $allReposResponse | ForEach-Object { echo "LOG: $($_)" } </code>
  steps:
  - task: PowerShell@2
    inputs:
      targetType: 'inline'
      script: |
        $header = @{ Authorization = "Bearer $(System.AccessToken)" }
        $allReposUrl = "$($env:SYSTEM_TEAMFOUNDATIONSERVERURI)_apis/git/repositories?api-version=6.0"
        $allReposResponse = (Invoke-RestMethod -Uri $allReposUrl -Method Get -Headers $header).value

        $allReposResponse | ForEach-Object {
            echo "LOG: $($_)"
        }

When I try to echo the URL and open it in the browser, it displays the expected count and enumerates all the repos in the project. There is inconsistency on the results of the pipeline and on the browser.

I already adjusted the security settings for build service but still no avail. Am I missing on modifying the setup for the build service user?

Thank you for your help!

4

I have tested your yaml file, it works fine and returns all the repos in the current project. Please check and try the followings in your organization.

  1. Turn off the Protect access to repositories in YAML pipelines from Project Settings -> Pipeline Settings.

    With this option enabled, the scope of access for all pipelines will be reduced to only Azure DevOps repositories explicitly referenced by a checkout step or a uses statement in the pipeline job that uses that repository. See the details from Protect access to repositories in YAML pipelines.

  2. Please check whether your project has enabled Limit job authorization scope to current project for non-release pipelines from Project Settings -> Pipeline Settings. If this option is enabled, the build service account used is project-scoped. Otherwise, it’s collection-scoped.

    • The collection-scoped build service account name has format: Project Collection Build Service ({OrgName})
    • The project-scoped build service account name has format: {Project Name} Build Service ({Org Name})

    Assign your target build service account with the Read permission of all your repos. Go to Project Settings -> Repositories -> Security -> Search your build service account and set the Read permission to Allow.


Update

If you can’t turn off Protect access to repositories in YAML pipelines in the Pipeline Settings, you can create a PAT with vso.code scope and add it to the pipeline as a secret variable. Use it in your scripts for authentication.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
$token = "$(PAT)"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$header = @{ Authorization =" Basic $token" }
$allReposUrl = "$($env:SYSTEM_TEAMFOUNDATIONSERVERURI)_apis/git/repositories?api-version=6.0"
$allReposResponse = (Invoke-RestMethod -Uri $allReposUrl -Method Get -Headers $header).value
$allReposResponse | ForEach-Object {
echo "LOG: $($_)"
}
</code>
<code>- task: PowerShell@2 inputs: targetType: 'inline' script: | $token = "$(PAT)" $token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)")) $header = @{ Authorization =" Basic $token" } $allReposUrl = "$($env:SYSTEM_TEAMFOUNDATIONSERVERURI)_apis/git/repositories?api-version=6.0" $allReposResponse = (Invoke-RestMethod -Uri $allReposUrl -Method Get -Headers $header).value $allReposResponse | ForEach-Object { echo "LOG: $($_)" } </code>
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |      
      $token = "$(PAT)"
      $token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
      $header = @{ Authorization =" Basic $token" }
      $allReposUrl = "$($env:SYSTEM_TEAMFOUNDATIONSERVERURI)_apis/git/repositories?api-version=6.0"
      $allReposResponse = (Invoke-RestMethod -Uri $allReposUrl -Method Get -Headers $header).value

      $allReposResponse | ForEach-Object {
          echo "LOG: $($_)"
      }

1

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