2017-01-09 263 views
2

我刚开始学习groovy.I想在svn copy命令中将svnSourcePath和svnDestPath传递给shell脚本。但URL未呈现。将groovy变量传递给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 
+0

到低估了这个问题的人 - 没有给出解释就有什么意义? –

回答

4

加入围绕该变量的单引号和加算子( '+可变+')。现在它正在工作

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

您可以使用""" content $var """"""允许在这里doc的字符串插值; '''没有。

1

+1到Selvam答案

以下是我的使用情况和参数插件: 字符串参数名:pipelineParameter 默认值:4

node { 
    stage('test') { 
     withCredentials([[...]]) { 
      def pipelineValue = "${pipelineParameter}" //declare the parameter in groovy and use it in shellscript 
      sh ''' 
      echo '''+pipelineValue+' abcd'''' 
      ''' 
     } 
}} 

上面打印4 ABCD