繁体   English   中英

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

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

我有一个使用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" ])  
}

当执行此詹金斯作业时,它失败,因为'%20'被替换为'0' 日志说:

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

如何在詹金斯管道脚本中使用bat任务正确编码git url

您的%20字符很可能被解释为变量。 您有很多解决方案:

不允许变量替换

从蝙蝠脚本中删除插值。 为此,请使用simple quotes而不是double quotes

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

使用“ +”字符代替“%20”

加号不应解释为变量,而应作为URL中的空格有效:

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

转义解释的字符

我没有测试它,但很可能是与您的bat脚本一起使用的,它是%会被解释和替换。 为了避免这种情况,您可以尝试使用%%对其进行转义:

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

注意:根据本文%字符必须使用另一个%char进行转义,因此: %%

暂无
暂无

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

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