Found a solution, setting the variable within a 'script' block.
The variable is then available across all stages.

That was a ballache to find

    stage("Checkout") {
      steps {
        git url: "ssh://xxxxxxxxx.git", credentialsId: 'xxxxxxxxx'
        wrap([$class: 'BuildUser']) {
          script {
             USER_ID = "${BUILD_USER_ID}"
          }
        }
        echo "${USER_ID}"
      }
    }



On Tuesday, 19 September 2017 09:23:43 UTC+1, Russ Cox wrote:
>
> Cheers, yeah I have it set out like that currently but need to repeat this 
> for each and every stage and post section.
>
> Ideally I could set this variable in the 'environment' section so it's 
> available throughout the script
>
>
>
> On Thursday, 14 September 2017 00:01:47 UTC+1, Andrew Bayer wrote:
>>
>> Put the rest of your steps inside the {}
>>
>> A.
>>
>> On Tue, Sep 12, 2017 at 3:09 PM Russ Cox <[email protected]> wrote:
>>
>>> Hi, I'm using Jenkins to run a bunch of self service jobs and need to be 
>>> able to determine the user id of the person who ran a job.
>>>
>>> We've been doing this with the scripted pipeline up until now by using 
>>> the BuildUser plugin (quite why this isn't just a default exported variable 
>>> I don't know, other CI servers do)
>>>
>>>         wrap([$class: 'BuildUser']) {
>>>          sh 'echo "${BUILD_USER}"'
>>>          sh 'echo "${BUILD_USER_ID}"'
>>>          sh 'echo "${BUILD_USER_EMAIL}"'
>>>         }
>>>
>>> I can run the following within a step but the variable isn't available 
>>> to subsequent steps.
>>>
>>>       steps {
>>>         wrap([$class: 'BuildUser']) {
>>>          sh 'echo "${BUILD_USER}"'
>>>          sh 'echo "${BUILD_USER_ID}"'
>>>          sh 'echo "${BUILD_USER_EMAIL}"'
>>>         }
>>>         echo "${USER_ID}"
>>>
>>> Seems like there must be a way round this but can't find an answer in 
>>> documentation or google, any help would be great.
>>>
>>> -- 
>>> 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 [email protected].
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/jenkinsci-users/4be2dcc6-fc13-4e70-bbd4-96556f3d27d0%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/jenkinsci-users/4be2dcc6-fc13-4e70-bbd4-96556f3d27d0%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/de83af21-acf7-4697-a9bf-d7f6cccd169d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to