0

/var/coverityCompile.groovy

#!groovy
def java(String DIR) {
    compile_dir="${WORKSPACE}/${DIR}"
    echo "complie_dir:${compile_dir}"
    sh "echo complie_dir:${compile_dir}"
    sh '''
    echo complie_dir:${compile_dir}
    '''
}

/src/org/coverity/JenkinsFile

#!groovy
@Library('shared-library') _
   pipeline {
    agent { label 'dev_ci_env_dm' }
    stages {
        stage('coverity'){
            steps{
                script{
                    coverityCompile.java("DM")
                }

            }
        }
}
}

The Jenkins log will be:

complie_dir:/home/ci/workspace/test_coverity/DM
[Pipeline] sh
[test_coverity] Running shell script
+ echo complie_dir:/home/ci/workspace/test_coverity/DM
complie_dir:/home/ci/workspace/test_coverity/DM
complie_dir:

when I use echo "complie_dir:${compile_dir}" and sh "echo complie_dir:${compile_dir}" the result will be printed as expected. But, when I use

sh '''
    echo complie_dir:${compile_dir}
'''

The result of ${compile_dir} will be null. Now, I want to execute multiline of shell,so is there any other way to replace sh ''' '''?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Z.yue
  • 1
  • 2
    `'` does not interpolate variables. You need `"`. – Matthew Schuchard Jun 26 '18 at 12:24
  • 2
    Possible duplicate of [What's the difference of strings within single or double quotes in groovy?](https://stackoverflow.com/questions/6761498/whats-the-difference-of-strings-within-single-or-double-quotes-in-groovy) – mkobit Jun 26 '18 at 12:53

0 Answers0