Swa*_*wal 2 groovy oauth-2.0 jenkins gitlab jenkins-groovy
我无法使用 https 上的 oauth2 令牌通过 jenkins groovy 从 gitlab 签出代码。
使用相同的 oauth 令牌在 git cli 上进行克隆。我还可以通过同一台计算机上的curl 列出我的所有Gitlab 项目。
但无法通过 groovy 管道使用 Oauth2 令牌调用 git clone。
约束:Jenkins 服务器需要通过 groovy 脚本使用 oauth2 令牌通过 https 端口(仅)与 gitlab 服务器进行通信。我想使用 jenkins 凭证管理器来存储 Oauth2 令牌 - 而不是直接通过 s 脚本传递它
错误:状态代码 128:stderr:远程:HTTP 基本:访问被拒绝
**用于结帐的 Groovy 代码 **
checkout([$class: 'GitSCM', branches: [[name: "*/$GIT_BRANCH"]], doGenerateSubmoduleConfigurations: false, extensions: [], gitTool: 'Default', submoduleCfg: [], userRemoteConfigs: [[credentialsId: "$GIT_CREDS_ID", url: "$GIT_URL"]]])
Run Code Online (Sandbox Code Playgroud)
问题是 $GIT_CREDS_ID :仅选择具有 SSH 私钥或用户名/密码组合的凭证 ID。但不选择具有 Oauth 令牌的凭证 ID(安装 git lab 插件后创建)
错误 :
Warning: CredentialId "2002" could not be found. # same is being listed under jenkins credentials
> git rev-parse --is-inside-work-tree # timeout=10
...
Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --progress https://git.my-gitlab-site.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout:
stderr: remote: HTTP Basic: Access denied
fatal: Authentication failed for 'https://git.my-gitlab-site.git/'
Run Code Online (Sandbox Code Playgroud)
相同的oauth令牌通过curl,git cli可以正常工作,即使我直接在git的https url中传递它,例如: https://oauth2:SomeDummyToken@git.aa.st/c-swajai/poc_devops_coe.git
但无法通过詹金斯使用相同的功能。
系统详细信息 Jenkins 版本。2.172
操作系统“Amazon Linux”版本“2”
| 归档时间: |
|
| 查看次数: |
5847 次 |
| 最近记录: |