Pass groovy variable to shell script

前端 未结 5 2132
没有蜡笔的小新
没有蜡笔的小新 2020-12-06 13:38

I just started learning groovy.I want to pass the svnSourcePath and svnDestPath to shell script in the svn copy command. But URL not rendered.

node {
 stage          


        
相关标签:
5条回答
  • 2020-12-06 13:57

    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 '''
    
    0 讨论(0)
  • 2020-12-06 14:00

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

    0 讨论(0)
  • 2020-12-06 14:00

    only one time double quotes would also work

    stage('test') {  
      steps {  
        script {  
          for(job in env.JOB_NAMES.split(',')) {  
            println(job);  
            sh "bash jenkins/script.sh $job"  
            sh "echo $job"  
          }  
        }//end of script  
      }//end of steps  
    }//end of stage test
    
    0 讨论(0)
  • 2020-12-06 14:07

    +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

    0 讨论(0)
  • 2020-12-06 14:14
    def my_var = "hai"
    sh (
        script:  "echo " + my_var,
        returnStdout: true
    )
    
    0 讨论(0)
提交回复
热议问题