使用作业参数连接和回显设置变量的方法不起作用。作业参数是rp,即" WEB_SERVICE" 我有组合打印变量commandPRM与双引号,单引号等,但没有工作。我想要做的是运行命令dir WEB_SERVICE并根据结果从工作区中删除该文件夹。 设置和打印用户定义变量时出现问题。
我的管道代码段就像这样
script {
bat 'echo %rp%'
def commandPRM='%rp%'
bat 'echo variable 1'
script {
bat 'echo variable 2'
bat("echo %commandPRM%")
}
commandPRM='dir '+commandPRM + ' /s /q'
script {
bat 'echo variable 3'
bat("echo %commandPRM%")
bat 'echo variable 4'
bat('echo %commandPRM%')
}
bat(script: 'commandPRM ; echo $? > status')
println 'Performing print action...1'
def r = readFile('status').trim()
println r
println 'Performing print action...2'
if (r==0 ) {
println 'Performing some action...3'
bat('rmdir '+ '%rp%' + ' /s /q')
}
}
,输出低于
[Pipeline] {
[Pipeline] stage
[Pipeline] { (CleanWS)
[Pipeline] script
[Pipeline] {
[Pipeline] bat
[PRA_4_NET_WINDOWS] Running batch script
C:\HudSlvNEW\workspace\PRA_4_NET_WINDOWS>echo WEB_SERVICE
WEB_SERVICE
[Pipeline] bat
[PRA_4_NET_WINDOWS] Running batch script
C:\HudSlvNEW\workspace\PRA_4_NET_WINDOWS>echo variable 1
variable 1
[Pipeline] script
[Pipeline] {
[Pipeline] bat
[PRA_4_NET_WINDOWS] Running batch script
C:\HudSlvNEW\workspace\PRA_4_NET_WINDOWS>echo variable 2
variable 2
[Pipeline] bat
[PRA_4_NET_WINDOWS] Running batch script
C:\HudSlvNEW\workspace\PRA_4_NET_WINDOWS>echo
ECHO is on.
[Pipeline] }
[Pipeline] // script
[Pipeline] script
[Pipeline] {
[Pipeline] bat
[PRA_4_NET_WINDOWS] Running batch script
C:\HudSlvNEW\workspace\PRA_4_NET_WINDOWS>echo variable 3
variable 3
[Pipeline] bat
[PRA_4_NET_WINDOWS] Running batch script
C:\HudSlvNEW\workspace\PRA_4_NET_WINDOWS>echo
ECHO is on.
[Pipeline] bat
[PRA_4_NET_WINDOWS] Running batch script
C:\HudSlvNEW\workspace\PRA_4_NET_WINDOWS>echo variable 4
variable 4
[Pipeline] bat
[PRA_4_NET_WINDOWS] Running batch script
C:\HudSlvNEW\workspace\PRA_4_NET_WINDOWS>echo
ECHO is on.
[Pipeline] }
[Pipeline] // script
[Pipeline] bat
[PRA_4_NET_WINDOWS] Running batch script
C:\HudSlvNEW\workspace\PRA_4_NET_WINDOWS>commandPRM ; echo $? 1>status
'commandPRM' is not recognized as an internal or external command,
operable program or batch file.
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
答案 0 :(得分:0)
因为commandPRM是一个groovy变量,所以不需要将它放在百分之间。这种方式有效
bat(“echo”+ commandPRM)