Pass groovy variable to shell script

别等时光非礼了梦想. 提交于 2019-11-30 20:47:24

added the single quotes and plus operater('+ variable +') around the variable. Now it is working

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

+1 to Selvam answer

following is my use case with parameter plugin

String parameter name: pipelineParameter

Default value: 4

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

The above prints 4 abcd

You can use """ content $var """. """ allows string interpolation in the here doc; ''' does not.

def my_var = "hai"
sh (
    script:  "echo " + my_var,
    returnStdout: true
)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!