pipelines: how to store script output into a variable?

26 views
Skip to first unread message

Pa Y

unread,
Oct 23, 2019, 7:40:25 AM10/23/19
to Jenkins Users
Hi,
I looked extensively and the standard solution found in SO or other places doesn't work for me.. do you know what is the problem and how to fix it?

thanks for any help in advance!

a sample pipeline:
---
pipeline {
    agent any
    environment {
        JAVA_INFO= ""
    }
    stages {
        stage('test read info') {
            steps {
                script {
                    JAVA_INFO = sh(returnStdout: true, script: "java -version")
                    sh("echo this is java: ${JAVA_INFO}")
                }
            }
        }
    }
}
-----------

EXPECTED OUTPUT:

this is java: openjdk version "11.0.4" 2019-07-16
... (more lines)


CURRENT OUTPUT:  (echo is empty)
[Pipeline] sh
+ java -version
openjdk version "11.0.4" 2019-07-16
OpenJDK Runtime Environment (build 11.0.4+11-post-Debian-1deb10u1)
OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Debian-1deb10u1, mixed mode, sharing)
[Pipeline] sh
+ echo this is java:
this is java:
[Pipeline] }
[Pipeline] // script

Regards,
Pablo

Reinhold Füreder

unread,
Oct 23, 2019, 8:40:10 AM10/23/19
to jenkins...@googlegroups.com

Hi,

 

the „funny“ answer is:

„java -version” prints the version information to stderr…

 

HTH Reinhold

--
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/383d7586-8a5c-4d57-82c3-56ba9ce71ece%40googlegroups.com.

Pa Y

unread,
Oct 23, 2019, 9:51:41 AM10/23/19
to Jenkins Users
oh, wow, thank you Rheinhold! vielen Dank!

I see there is also a feature request to "Allow sh to return exit status, stdout and stderr all at once"

To unsubscribe from this group and stop receiving emails from it, send an email to jenkins...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages