简体   繁体   English

Jenkins Pipeline Groovy脚本:批处理脚本问题'%20'被替换为'0'

[英]Jenkins Pipeline Groovy script: batch script issue '%20' is replaced with '0'

I have a pipeline script using a git URL with whitespaces https://username:password@project-teamprojects.visualstudio.com/defaultcollection/_git/Core - Stream : 我有一个使用git URL和空格的管道脚本https://username:password@project-teamprojects.visualstudio.com/defaultcollection/_git/Core - Stream

node ("master") {
  bat([script: "git push https://username:password@project-teamprojects.visualstudio.com/defaultcollection/_git/Core%20-%20Stream", encoding: "UTF-8" ])  
}

When this jenkins job is executed, it fails because '%20' is replaced with '0' . 当执行此詹金斯作业时,它失败,因为'%20'被替换为'0' Log saying that: 日志说:

git push https://username:password@project-teamprojects.visualstudio.com/defaultcollection/_git/Core0-0Stream 
remote: TF401019: The Git repository with name or identifier Core0-0Stream does not exist or you do not have permissions for the operation you are attempting.
fatal: repository 'https://username:password@project-teamprojects.visualstudio.com/defaultcollection/_git/Core0-0Stream/' not found

How to encode git url properly using bat task in jenkins pipeline script 如何在詹金斯管道脚本中使用bat任务正确编码git url

Your %20 character is most probably interpreted as a variable. 您的%20字符很可能被解释为变量。 You have a lot of solutions : 您有很多解决方案:

Do not allow variable substitution 不允许变量替换

Remove interpolation from your bat script. 从蝙蝠脚本中删除插值。 For that, use simple quotes instead of double quotes : 为此,请使用simple quotes而不是double quotes

bat([script: 'git push https://username:password@project-teamprojects.visualstudio.com/defaultcollection/_git/Core%20-%20Stream', encoding: "UTF-8" ]) 

Use '+' char instead of '%20' 使用“ +”字符代替“%20”

Plus sign should not be interpreted as a variable and should be valid as a space in URL : 加号不应解释为变量,而应作为URL中的空格有效:

bat([script: "git push https://username:password@project-teamprojects.visualstudio.com/defaultcollection/_git/Core+-+Stream", encoding: "UTF-8" ]) 

Escape the interpreted character 转义解释的字符

I didn't test it but most probably with your bat script it's the % that gets interpreted and replaced. 我没有测试它,但很可能是与您的bat脚本一起使用的,它是%会被解释和替换。 To avoid that you could try to escape it with a %% : 为了避免这种情况,您可以尝试使用%%对其进行转义:

bat([script: "git push https://username:password@project-teamprojects.visualstudio.com/defaultcollection/_git/Core%%20-%%20Stream", encoding: "UTF-8" ]) 

Note : According to this article , % character must be escaped with another percent char, so : %% . 注意:根据本文%字符必须使用另一个%char进行转义,因此: %%

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM