【问题标题】:Checkout a private github in Azure pipeline job using service connection使用服务连接在 Azure 管道作业中签出私有 github
【发布时间】:2020-01-08 12:51:15
【问题描述】:

我想在 Azure 管道阶段之一中签出位于同一 GitHub 组织中的私有存储库之一,基于 Azure 文档,这是我尝试过的:

https://docs.microsoft.com/en-us/azure/devops/pipelines/repos/multi-repo-checkout?view=azure-devops

resources:
  repositories:
  - repository: pipelinetemplates
    type: github
    name: myorg/myrepotemplate
    endpoint: mygithub-serviceconnection
  - repository: myrepo
    type: github
    name: myorg/myrepo
    endpoint: mygithub-serviceconnection
stages:
- stage:
  jobs:
  - job: Build
    steps:
    - template: Template/build.yaml@pipelinetemplates ##It works fine
    pool:
       vmImage: 'ubuntu-latest'

- stage:
  jobs:
   - job: A
     pool:
       vmImage: 'ubuntu-latest'
     steps:
     - checkout: myrepo  ##Error-not found repo
     - task: PowerShell@2
       inputs:
        targetType: 'inline'
        script: |
          Write-Host "Fetching files"
          ls

我在结帐部分收到此错误消息:

Syncing repository: myorg/myrepo (github)
git version
git version 2.24.0
git lfs version
git-lfs/2.9.1 (GitHub; linux amd64; go 1.13.1)
git init "/home/vsts/work/1/s"
Initialized empty Git repository in /home/vsts/work/1/s/.git/
git remote add origin https://github.com/myorg/myrepo
git config gc.auto 0
git config --get-all http.https://github.com/myorg/myrepo.extraheader
git config --get-all http.proxy
git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules origin
remote: Repository not found.
fatal: repository 'https://github.com/myorg/myrepo/' not found
##[warning]Git fetch failed with exit code 128, back off 5.284 seconds before retry.

有谁知道问题是什么以及如何解决?

更新:

我可以看到服务连接正在使用 GitHub-InstallationToken(使用 azure 管道应用程序)。根据我使用 GitHub 令牌时的最后一次搜索,我们不能多次使用它来获取一个管道下的存储库,但是在这个管道中,我们调用了 GitHub 服务连接两次。看起来令牌是一次有效的。有没有办法解决这个问题?

【问题讨论】:

  • 您确定您的服务连接有权访问该存储库吗?这看起来不错
  • 是的,我使用相同的服务连接从另一个 repo 中获取 helmchart 模板,它以这种方式工作正常,但是使用结帐时出现问题。
  • 服务连接的账号和github账号一样吗?如果没有,用于服务连接的帐户是否可以访问github上的私有存储库?尝试添加协作者或通过 Github PAT 创建服务连接。
  • @LeoLiu-MSFT 是的,服务连接是 GitHub 用户。并且该用户具有对私有存储库的读取权限。
  • @LeoLiu-MSFT 如何添加合作者?

标签: github azure-devops azure-pipelines git-checkout


【解决方案1】:

使用 oauth 而不是 oauth2 重新设置 GitHub 服务连接解决了问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-10
    • 2020-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多