将 azure DevOps 与 Github 集成

问题描述 投票:0回答:1

我日常使用 azure devops 来提交和推送代码,但构建 dockerfile 和 ECS 的代码位于 github 中。

有没有一种方法可以让我在 Azure DevOps 中所做的每个提交都直接转到 github!

我在管道中执行了这些步骤:

schedules:
- cron: "0 * * * *" # Runs every hour
  displayName: Daily deployment
  branches:
    include:
    - develop
  always: true

variables:
- group: GitHubPAT

jobs:
- job: DeployToGitHub
  pool:
    vmImage: 'ubuntu-latest'
  steps:
  - checkout: self
    persistCredentials: true

  - script: |
      git config --global user.email "[email protected]"
      git config --global user.name "enluad"
      git fetch origin develop
      git checkout develop
      git add .
      git remote add github https://${GitHubPAT}@github.com/username/projectname
      git push github HEAD:develop --force

    displayName: 'Push to GitHub'
    env:
      GitHubPAT: $(GitHubPAT)

但是这条管道给了我这个错误:

From https://dev.azure.com/xxx/yyy/_git/monorepo
 * branch            develop    -> FETCH_HEAD
 * [new branch]      develop    -> origin/develop
Previous HEAD position was ebf78c3 Update pipeline.yml for Azure Pipelines
Switched to a new branch 'develop'
branch 'develop' set up to track 'origin/develop'.
remote: Write access to repository not granted.
fatal: unable to access 'https://github.com/username/projectname/': The requested URL returned error: 403
github azure-devops devops
1个回答
0
投票

远程:未授予对存储库的写访问权限。致命:无法访问'https://github.com/username/projectname/':请求的URL返回错误:403

从错误信息来看,问题原因可能是Github PAT token没有写权限。

要解决此问题,您需要创建一个新的Github令牌并授予该令牌repo写入权限。

例如:导航至 Github 设置 -> 个人访问令牌(经典) -> 生成新令牌(经典)

然后您可以选择repo读写权限来生成PAT令牌。

例如:

您可以在 Azure Pipeline 中使用新的 Github PAT 令牌来运行 git 命令。

有没有一种方法可以让我在 Azure DevOps 中所做的每个提交都直接转到 github!

在 Azure DevOps Pipeline 中,您可以为管道设置 CI 触发器

例如:

trigger:
- main
- releases/*

当触发分支有新的提交时,会自动触发管道将提交同步到Github Repo。

© www.soinside.com 2019 - 2024. All rights reserved.