我无法通过https通过jenkins groovy使用oauth2令牌从gitlab签出代码。
克隆使用相同的oauth令牌在git cli上运行。我也可以在同一台机器上通过curl列出我的所有Gitlab项目。
但无法通过groovy管道使用Oauth2令牌调用git clone。
约束:Jenkins服务器需要通过https端口(仅)与gitlab服务器通过groovy脚本使用oauth2令牌进行通信。我想使用jenkins凭证管理器来存储Oauth2令牌 - 而不是直接通过s脚本传递它
错误:状态码128:stderr:remote:HTTP Basic:拒绝访问
** Groovy代码用于结账**
checkout([$class: 'GitSCM', branches: [[name: "*/$GIT_BRANCH"]], doGenerateSubmoduleConfigurations: false, extensions: [], gitTool: 'Default', submoduleCfg: [], userRemoteConfigs: [[credentialsId: "$GIT_CREDS_ID", url: "$GIT_URL"]]])
问题是$ 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/'
相同的oauth令牌通过curl,git cli工作正常,即使我直接在git的https url中传递它:https://oauth2:[email protected]/c-swajai/poc_devops_coe.git
但是不能通过詹金斯使用相同的。
系统详情Jenkins ver。 2.172
操作系统“亚马逊Linux”版本“2”
发现了一个相关的bug:https://issues.jenkins-ci.org/browse/JENKINS-36863
我找到了一个相关的oldbug(状态:已解决),似乎已在最新版本的jenkins中重新出现。针对类似问题的其他人的解决方法。
创建用户名和密码类型的新凭据
用户名:AnyRandomString 密码:YourOauthToken 凭据ID:任何自定义数字/字符串
克隆时在groovy脚本中使用上述凭证ID。现在,您可以使用Oauth tokem在443端口上使用https url克隆git