2017-01-09 299 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