【发布时间】:2019-07-01 22:31:07
【问题描述】:
在我们的一个 Azure Pipelines 中,我尝试将标签推送到 GitHub,但根据我的方法收到两个错误之一。
没有认证,只是一个简单的git push
- bash: 'git push origin $(tag)'
git push origin 2019.07.01.1
fatal: could not read Username for 'https://github.com': terminal prompts disabled
将AUTHORIZATION: Bearer *** 作为额外的标头传递
- bash: 'git -c http.extraheader="AUTHORIZATION: Bearer $(System.AccessToken)" push origin $(tag)'
git -c http.extraheader="AUTHORIZATION: Bearer ***" push origin 2019.07.01.2
fatal: unable to access 'https://github.com/respondentinc/website/': The requested URL returned error: 400
使用环境变量将AUTHORIZATION: Bearer *** 作为额外的标头传递
发件人:https://github.com/microsoft/azure-pipelines-agent/issues/1582#issuecomment-392235276
- bash: 'git -c http.extraheader="AUTHORIZATION: Bearer $env:token" push origin $(tag)'
env:
token: $(System.AccessToken)
git -c http.extraheader="AUTHORIZATION: Bearer ***" push origin 2019.07.01.3
fatal: unable to access 'https://github.com/respondentinc/website/': The requested URL returned error: 400
将 Bash 脚本传递给凭证助手
基于bk2204的回答
- bash: 'git -c credential.helper=''!f() { echo "username=token"; echo "password=$(System.AccessToken)"; }; f'' push origin $(tag)'
git -c credential.helper='!f() { echo "username=token"; echo "password=***"; }; f' push origin 2019.07.02.9
fatal: unable to access 'https://github.com/respondentinc/website/': The requested URL returned error: 400
使用环境变量将 Bash 脚本传递给凭证助手
来自bk2204的回答
- bash: 'git -c credential.helper=''!f() { echo "username=token"; echo "password=$env:token"; }; f'' push origin $(tag)'
env:
token: $(System.AccessToken)
git -c credential.helper='!f() { echo "username=token"; echo "password=$env:token"; }; f' push origin 2019.07.02.9
fatal: unable to access 'https://github.com/respondentinc/website/': The requested URL returned error: 400
将AUTHORIZATION: Basic *** 作为额外的标头传递
试图模仿默认管道“结帐”任务的方式。
- bash: 'git -c http.extraheader="AUTHORIZATION: basic $(System.AccessToken)" push origin $(tag)'
git -c http.extraheader="AUTHORIZATION: basic ***" push origin 2019.07.02.10
fatal: unable to access 'https://github.com/respondentinc/website/': The requested URL returned error: 400
我在上述主题上尝试了一些变体,但都没有成功。
我错过了什么?
更新:2019-07-02
上述所有机制都是有效的身份验证方式。问题是 System.AccessToken 对 GitHub 无效。 documentation 表示它仅用于与 Azure Pipeline 服务交互。
我找不到Azure Pipeline GitHub App 提供的令牌的变量。我认为这并不重要,因为它是installation token。我尝试将此令牌与 GitHubRelease 任务一起使用,但由于缺少写入权限,它仍然失败。
为了完成这项工作,我执行了 GitHubRelease 任务,并且必须使用具有写入权限的新 OAuth 令牌创建新服务连接。
我仍然很好奇如何从 Bash 任务中访问与服务连接关联的令牌。
【问题讨论】:
-
我也有同样的问题。你找到解决办法了吗?
-
@Maxim 我使用了 GitHubRelease 任务并专门为此工作创建了一个 OAuth 令牌(在 GitHub 内)。不理想。我计划很快迁移到 GitHub Actions。
-
我已添加我的解决方案作为答案。
标签: git azure-pipelines