Q:

How to store a bash standard out in an env variable

I try to set up a Job in Jenkins that executes a shell script on a remote host using ssh, and store parts of the output (a path to a file on said server) in an env variable for further use in other steps. AT the moment, I have no idea, if i should try to use the pipeline plugin, or store the output somehow in a file.
i would appreciate any suggestions, on how to do this.

A:

In my case i store it in a file then read it as environment variable.
So for example lets get the git revision value and use it as environment variable, i will assume that we are already inside a cloned git repository
stage('Get Git Revision') {
    steps {
        script {
            ...
            sh 'git log --pretty=format:\'%h\' -n 1 > ../GIT_REVISION'
            env.GIT_REVISION = readFile 'GIT_REVISION'
            sh 'echo $GIT_REVISION'
            ...
        }
    }
    ....
}

You can remove GIT_REVISION file later or let it to be deleted within cleanWs()

