Trouble getting user id variable on builds

2,282 views
Skip to first unread message

samuel....@madeiramadeira.com.br

unread,
May 29, 2017, 1:53:33 PM5/29/17
to Jenkins Users
Hi, I need access to a Jenkins variable that defines the user who started the build.

It is essential for my usecase because i need to pass it to capistrano and newrelic, in order to log who did it.

I stumbled upon the Build User Vars Plugin[1], but it appears that it doesn't work, i can't seem to find the 'Set Jenkins user build variables' option.
I also found this[2] post explaining a different approach to use it on a pipeline script, which didn't work:

Started by user Samuel Henrique
[Pipeline] node
Running on master in /var/lib/jenkins/workspace/deploy-teste2
[Pipeline] {
[Pipeline] wrap
[Pipeline] // wrap
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
java.lang.UnsupportedOperationException: no known implementation of class jenkins.tasks.SimpleBuildWrapper is named BuildUser
	at org.jenkinsci.plugins.structs.describable.DescribableModel.resolveClass(DescribableModel.java:427)
	at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:379)
	at org.jenkinsci.plugins.structs.describable.DescribableModel.buildArguments(DescribableModel.java:318)
	at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:259)
	at org.jenkinsci.plugins.workflow.steps.StepDescriptor.newInstance(StepDescriptor.java:201)
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:203)
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:148)
	at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:108)
	at groovy.lang.GroovyObject$invokeMethod.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:151)
	at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:21)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:115)
	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:149)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:146)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:123)
	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:16)
Caused: java.lang.IllegalArgumentException: Could not instantiate {delegate={$class=BuildUser}} for CoreWrapperStep(delegate: SimpleBuildWrapper{TimestamperBuildWrapper() | Xvfb(additionalOptions?: String, assignedLabels?: String, autoDisplayName?: boolean, debug?: boolean, displayName?: int, displayNameOffset?: int, installationName?: String, parallelBuild?: boolean, screen?: String, shutdownWithBuild?: boolean, timeout?: long) | Xvnc(takeScreenshot: boolean, useXauthority: boolean)})
	at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:264)
	at org.jenkinsci.plugins.workflow.steps.StepDescriptor.newInstance(StepDescriptor.java:201)
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:203)
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:148)
	at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:108)
	at groovy.lang.GroovyObject$invokeMethod.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:151)
	at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:21)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:115)
	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:149)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:146)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:123)
	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:16)
	at WorkflowScript.run(WorkflowScript:2)
	at ___cps.transform___(Native Method)
	at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57)
	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82)
	at sun.reflect.GeneratedMethodAccessor325.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
	at com.cloudbees.groovy.cps.impl.ClosureBlock.eval(ClosureBlock.java:46)
	at com.cloudbees.groovy.cps.Next.step(Next.java:74)
	at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:154)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:33)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:30)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:30)
	at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:165)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:330)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:82)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:242)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:230)
	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE

It is really surprising how difficult it is to get a simple variable such as the user identification of who started the build on Jenkins.

Can anybody help me? I bet there's more people with this problem.

I'm using the last Jenkins release, 2.63

[1]https://wiki.jenkins-ci.org/display/JENKINS/Build+User+Vars+Plugin
[2]https://support.cloudbees.com/hc/en-us/articles/226287607-How-to-use-Build-User-Vars-Plugin-with-Pipeline

samuel....@madeiramadeira.com.br

unread,
Jun 22, 2017, 9:37:10 AM6/22/17
to Jenkins Users
Does anybody know where can i get help on this?

Getting the build user id is something someone already needed some time in the past for sure.

Saranjeet Singh

unread,
May 2, 2018, 3:32:31 AM5/2/18
to Jenkins Users
Hello, 

I am also getting same error. Anyone can help on this issue. Thanks

Victor Martinez

unread,
May 2, 2018, 4:35:04 AM5/2/18
to Jenkins Users
Can you confirm whether https://wiki.jenkins.io/display/JENKINS/Build+User+Vars+Plugin has been installed?

___ONLY_FOR_TRACKING_PURPOSES____

I just tried: as suggested in one of the URLs you posted, and it works like a charm:

pipeline {
  agent any

  stages
{
    stage
('build user') {
      steps
{
        wrap
([$class: 'BuildUser']) {
          sh
'echo "${BUILD_USER}"'
       
}
     
}
   
}
 
}
}


With the latest weekly version of the jenkins core (Jenkins ver. 2.119) and the below plugins:

ace-editor 1.1
ant 1.8
antisamy-markup-formatter 1.5
apache-httpcomponents-client-4-api 4.5.5-2.0
authentication-tokens 1.3
bouncycastle-api 2.16.2
branch-api 2.0.20
build-timeout 1.19
build-user-vars-plugin 1.5
cloudbees-folder 6.4
command-launcher 1.2
credentials 2.1.16
credentials-binding 1.16
display-url-api 2.2.0
docker-commons 1.11
docker-workflow 1.15.1
durable-task 1.22
email-ext 2.62
git 3.8.0
git-client 2.7.1
git-server 1.7
github 1.29.0
github-api 1.90
github-branch-source 2.3.4
gradle 1.28
handlebars 1.1.1
jackson2-api 2.8.11.1
jdk-tool 1.1
jquery-detached 1.2.1
jsch 0.1.54.2
junit 1.24
ldap 1.20
mailer 1.21
mapdb-api 1.0.9.0
matrix-auth 2.2
matrix-project 1.13
momentjs 1.1.1
pam-auth 1.3
pipeline-build-step 2.7
pipeline-github-lib 1.0
pipeline-graph-analysis 1.6
pipeline-input-step 2.8
pipeline-milestone-step 1.3.1
pipeline-model-api 1.2.9
pipeline-model-declarative-agent 1.1.1
pipeline-model-definition 1.2.9
pipeline-model-extensions 1.2.9
pipeline-rest-api 2.10
pipeline-stage-step 2.3
pipeline-stage-tags-metadata 1.2.9
pipeline-stage-view 2.10
plain-credentials 1.4
resource-disposer 0.8
scm-api 2.2.7
script-security 1.44
ssh-credentials 1.13
ssh-slaves 1.26
structs 1.14
subversion 2.10.5
timestamper 1.8.9
token-macro 2.5
workflow-aggregator 2.5
workflow-api 2.27
workflow-basic-steps 2.7
workflow-cps 2.49
workflow-cps-global-lib 2.9
workflow-durable-task-step 2.19
workflow-job 2.20
workflow-multibranch 2.18
workflow-scm-step 2.6
workflow-step-api 2.14
workflow-support 2.18
ws-cleanup 0.34


Cheers

Saranjeet Singh

unread,
May 2, 2018, 9:29:17 AM5/2/18
to Jenkins Users
Hi Victor,

I already installed mentioned plugin and it works. 
Thanks :)
Reply all
Reply to author
Forward
0 new messages