Jenkins多分支流水线中GitLab插件的URL编码问题求助
解决Jenkins GitLab插件SSH URL编码异常导致
checkout scm失败问题 问题场景
我们在为SFDX项目搭建CI/CD流水线时,采用GitLab作为源码仓库,Jenkins多分支流水线负责部署。配置GitLab插件后,使用SSH密钥认证克隆项目时,流水线中的checkout scm命令报错,错误日志显示Git URL被错误编码。
错误日志
Selected Git installation does not exist. Using Default The recommended git tool is: NONE using credential id_ed25519 > C:\Program Files\Git\bin\git.exe rev-parse --resolve-git-dir D:\Jenkins\workspace\LI-DevOps_main@2\.git # timeout=10 Fetching changes from the remote Git repository > C:\Program Files\Git\bin\git.exe config remote.origin.url %255bgit@gitlab.com:22222]:akashkhichi/salesforceproject.git # timeout=10 Fetching without tags Fetching upstream changes from %255bgit@gitlab.com:22222]:akashkhichi/salesforceproject.git > C:\Program Files\Git\bin\git.exe --version # timeout=10 > git --version # 'git version 2.22.0.windows.1' > C:\Program Files\Git\bin\git.exe fetch --no-tags --force --progress -- %255bgit@gitlab.com:22222]:akashkhichi/salesforceproject.git +refs/heads/main:refs/remotes/origin/main # timeout=10 ERROR: Error fetching remote repo 'origin' hudson.plugins.git.GitException: Failed to fetch from %255bgit@gitlab.com:22222]:akashkhichi/salesforceproject.git
问题分析
原SSH URL [git@gitlab.com:22222]:akashkhichi/salesforceproject.git 被双重错误编码:方括号[先被转义为%5b,随后又被二次编码为%255b,导致Git无法识别合法的仓库地址。已验证GitLab URL配置正确、SSH密钥功能正常,且单独使用Git插件可完成克隆,但因依赖GitLab插件的专属功能(如Webhook触发、合并请求集成等),需针对性解决该编码问题。
解决方案
1. 修正GitLab项目URL格式
Git的SSH URL不需要用方括号包裹,改用标准格式:
- 若使用默认SSH端口(22):
git@gitlab.com:akashkhichi/salesforceproject.git - 若使用非默认端口22222,正确的带端口SSH URL格式应为:
修改Jenkins中GitLab项目的URL配置,去掉方括号并采用上述标准格式。ssh://git@gitlab.com:22222/akashkhichi/salesforceproject.git
2. 手动指定仓库URL跳过自动编码
在流水线脚本中替换checkout scm为手动配置的GitSCM参数,避免插件自动编码:
checkout([ $class: 'GitSCM', branches: [[name: '*/main']], userRemoteConfigs: [[ url: 'ssh://git@gitlab.com:22222/akashkhichi/salesforceproject.git', credentialsId: 'id_ed25519' ]] ])
3. 升级插件版本
该编码异常可能是GitLab插件与Git插件版本不兼容导致的旧bug,将Jenkins的GitLab插件和Git插件升级到最新稳定版,即可修复部分编码逻辑问题。
4. 检查凭证配置
确认Jenkins中存储的SSH凭证仅包含密钥本身,没有多余的方括号或特殊字符;仓库的端口信息需单独配置在URL中,不要混入凭证内容。
内容的提问来源于stack exchange,提问作者Ritvik Bhomia
相关产品推荐
相关产品推荐

