How to get owner of upstream build in downstream build without using parameter?

29 views
Skip to first unread message

Gajanan Mahajan

unread,
Aug 4, 2020, 2:04:45 AM8/4/20
to Jenkins Users
I have upstream and downstream pipelines and in downstream pipeline, I want to store user, who started upstream build, in downstream build variable.

I used following in downstream pipeline but it results into error - `java.lang.NullPointerException: Cannot invoke method getUserId() on null object`

    Owner = currentBuild.rawBuild.getCause(Cause.UserIdCause).getUserId()

One way is to store it in a variable in upstream pipeline and pass it as param to downstream pipeline but that is additional handling and considering my parameters list, it is little tricky.

Is there any way I can get user who started upstream build in downstream build without passing parameter?

Similarly, `JOB_NAME` and `BUILD_NUMBER` of upstream to downstream.

Krish S

unread,
Aug 4, 2020, 1:55:42 PM8/4/20
to jenkins...@googlegroups.com
You could try this : 

def owner = currentBuild.getBuildCauses(‘hudson.model.Cause$UserIDCause’)
manager.addShortText(“${Approval.userId[0]} ${Approval.userName}”)


Thanks, 

--
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/f4704e0d-5958-4075-bd00-e5666f2a127fo%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages