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

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

最佳答案

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

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/

10-10 03:00