shell inside a groovy script doesnt resolve variables ?

25 views
Skip to first unread message

b o b i

unread,
Apr 16, 2019, 4:23:22 PM4/16/19
to Jenkins Users
I cannot make the executed shell to resolve a predefined variable in my jenkins script.. I tried various syntax approaches w/o succcess. ..

Anybody could give me a hand?


String workspace
String addOn = "Path/To/Cmake.cmake"

node ('slave01') {
    workspace = pwd()
    String addOnAbsPath = "${workspace}/$toolchainCmake"
   
    stage ('Build') {
      
        // for some reason is not recognize, thats why
        sh "echo ${addOnAbsPath}"
        sh '''
            echo Path: '$addOnAbsPath'
           '''
        sh '''#!/bin/bash
           echo ${addOnAbsPath}
           cmake ... -DADD_ON=$addOnAbsPath ...
        '''
    }
}

Jan Monterrubio

unread,
Apr 16, 2019, 6:34:01 PM4/16/19
to jenkins...@googlegroups.com
You might need to set up that variable as an environment variable for the shell to recognize it 


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/01535995-02a9-46ce-8388-ca01695dbbb9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel Butler

unread,
Apr 17, 2019, 5:21:19 AM4/17/19
to jenkins...@googlegroups.com


Strings using single quotes do not do variable expansion; you must use double quotes to have the variables expand.
So:
'$var' is the literal string $var
"$var" expands to the string value of the variable $var

and the same is true for multi line strings
'''----
$var
----'''
does not expand

"""----
$var
----"""
expands the value of $var




Reply all
Reply to author
Forward
0 new messages