build user id in declarative pipeline

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

build user id in declarative pipeline

Russ Cox
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/4be2dcc6-fc13-4e70-bbd4-96556f3d27d0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: build user id in declarative pipeline

Andrew Bayer
Put the rest of your steps inside the {}

A.

On Tue, Sep 12, 2017 at 3:09 PM Russ Cox <[hidden email]> 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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/4be2dcc6-fc13-4e70-bbd4-96556f3d27d0%40googlegroups.com.
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAPbPdOZoqM0esMVZnOMz4nPwXa95Yr8NnfFqvCb5LprHeTxsBg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: build user id in declarative pipeline

Russ Cox
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 <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="fg6m-lRtAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">russ...@...> 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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="fg6m-lRtAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-users/4be2dcc6-fc13-4e70-bbd4-96556f3d27d0%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/4be2dcc6-fc13-4e70-bbd4-96556f3d27d0%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/4be2dcc6-fc13-4e70-bbd4-96556f3d27d0%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-users/4be2dcc6-fc13-4e70-bbd4-96556f3d27d0%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/775cf718-f444-4c7d-83c3-44f8966faff5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: build user id in declarative pipeline

Russ Cox
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 <[hidden email]> 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 jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-users/4be2dcc6-fc13-4e70-bbd4-96556f3d27d0%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/4be2dcc6-fc13-4e70-bbd4-96556f3d27d0%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/4be2dcc6-fc13-4e70-bbd4-96556f3d27d0%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-users/4be2dcc6-fc13-4e70-bbd4-96556f3d27d0%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">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 [hidden email].
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.