Can shell variables be read outside of the shell block while in a script block?

18 views
Skip to first unread message

Idan Adar

unread,
Oct 14, 2017, 6:06:51 AM10/14/17
to Jenkins Users
script {
   
...
   
...
    sh
"""
        X = ...
    """

}


Can X be read directly, outside of the sh block?
Right now I'm echoing X to file (echo X > myfile.txt) and then read the contents of the file (def y = readFile("myfile.txt).trim).

There has to be a better way to do this?

Robert Hales

unread,
Oct 14, 2017, 5:09:45 PM10/14/17
to Jenkins Users
No, you can't set X in the shell and then read it in the script.  Sometimes I will get a variable by cat'ing the file back to the screen in another shell step and capture the stdout in a variable. 
Reply all
Reply to author
Forward
0 new messages