shell - 将 groovy 变量传递给 shell 脚本

标签 shell jenkins groovy cloudbees

我刚开始学习 groovy。我想在 svn copy 命令中将 svnSourcePath 和 svnDestPath 传递给 shell 脚本。但 URL 未呈现。

node {
 stage 'Copy Svn code'

def svnSourcePath = "${svnBaseURL}${svnAppCode}${svnEnvDev}${SVN_DEV_PACKAGE}"
def svnDestPath = "${svnBaseURL}${svnAppCode}${svnEnvTest}${SVN_DEV_PACKAGE}"

print "DEBUG: svnSourcePath = ${svnSourcePath}"
print "DEBUG: svnDestPath = ${svnDestPath}"

withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: crendentialsIdSVN, passwordVariable: 'SVN_PWD', usernameVariable: 'SVN_USER']]) {
    sh '''  
    svn copy $svnSourcePath $svnDestPath -m 'promote dev to test' --username $SVN_USER --password $SVN_PWD '''
}  
}

输出
+ svn copy -m 'promote dev to test' --username techuser --password 'xxxyyy' 
     svn: E205001: Try 'svn help' for more info
     svn: E205001: Not enough arguments provided

最佳答案

在变量周围添加了单引号和加号运算符('+ 变量 +')。现在它正在工作

svn copy '''+svnSourcePath+' '+svnDestPath+''' -m 'promote dev to test' --username $SVN_USER --password $SVN_PWD '''

关于shell - 将 groovy 变量传递给 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41553303/

相关文章:

shell - exit 语句不会中断 unix shell 中的 while 循环

jenkins - 如何在 Jenkins 作业生成器中使用 `inject-passwords`?

jenkins - Jenkins下的SignTool找不到与USB Token匹配的证书

grails - 如何通过 Grails 中的继承类中的映射构造函数设置属性?

linux - 在 unix 或 shell 中将新行打印为字符串文字

bash - 防止在 echo 参数中扩展\c

docker - Jenkins-Run Docker : COPY failed: stat/var/lib/docker/tmp/docker-builder. ..:没有这样的文件或目录

grails - 从 .js 文件创建指向资源的链接

java - 有没有办法编译隐藏源代码?

linux - 循环 Linux Shell 的空主体