Thanks Stuart!
Nick.

On Wednesday, October 29, 2014 12:43:56 PM UTC-7, Stuart Rowe wrote:
>
> Here you go :)
>
>
> import javax.mail.Message
> import hudson.model.*
> import com.cloudbees.plugins.flow.*
> import hudson.tasks.MailAddressResolver
>
> def getUpstreamBuild(AbstractBuild curBuild)
> {
>     upStreamBuild = null
>     if(curBuild != null)
>     {
>         // find a cause that will lead to an upstream build
>         for( cause in curBuild.causes )
>         {
>             if(cause instanceof Cause.UpstreamCause)
>             {
>                 upStreamBuild = 
> Hudson.instance.getItem(cause.upstreamProject).getBuildByNumber(cause.upstreamBuild)
>                 break
>             }
>             else if(cause instanceof FlowCause)
>             {
>                 upStreamBuild = cause.getFlowRun()
>                 break
>             }
>         }
>     }
>     return upStreamBuild
> }
>
> def getUserIdCause(AbstractBuild curBuild)
> {
>     def userIdCause = null
>     if (curBuild != null)
>     {
>         for( cause in curBuild.causes )
>         {
>             if(cause instanceof Cause.UserIdCause)
>             {
>                 userIdCause = cause
>                 break
>             }
>         }
>     }
>
>     return userIdCause
> }
>
> def getEmailFromUserId(userId)
> {
>     email = null
>     user = User.get(userId, false, [:])
>     if(user)
>     {
>         email = MailAddressResolver.resolve(user)
>     }
>     return email
> }
>
> def getRootRequesterUserEmail()
> {
>     try
>     {
>         // try to find a user ID cause for the current build
>         def userIdCause = getUserIdCause(build)
>         if(userIdCause != null)
>         {
>             return getEmailFromUserId(userIdCause.getUserId())
>         }
>
>         def rootBuild = null
>         def curUpstreamBuild = getUpstreamBuild(build)
>
>         // find the top level build
>         while(curUpstreamBuild)
>         {
>             rootBuild = curUpstreamBuild
>             curUpstreamBuild = getUpstreamBuild(curUpstreamBuild)
>         }
>
>         // try to find a user ID cause from the top level build
>         userIdCause = getUserIdCause(rootBuild)
>         if(userIdCause != null)
>         {
>             return getEmailFromUserId(userIdCause.getUserId())
>         }
>     }
>     catch (e)
>     {
>         println e
>     }
>     return  null
> }
>
> // update the recipients with the requester from the top level build
> def userEmail = getRootRequesterUserEmail()
> return userEmail
>
>
> On Tue, Oct 28, 2014 at 6:17 PM, Nick Dierauf <ndie...@gmail.com 
> <javascript:>> wrote:
>
>> Stuart, can you post the groovy script that you use to determine the 
>> email address (ie, "myscript.groovy")?
>> Thanks!
>> Nick.
>>
>>
>> On Tuesday, March 11, 2014 11:24:37 AM UTC-7, Stuart Rowe wrote:
>>>
>>> Hi, does anyone know of a way to look up a user's email address from 
>>> their user ID? I can't make the assumption that the email is "
>>> use...@company.com" because I know this isn't always the case.
>>>
>>> We're using the Active Directory plugin for security which is where the 
>>> email addresses for users are coming from. I need to manually add the 
>>> requester to the recipient list because this doesn't seem to be propagated 
>>> by BuildFlow FlowCauses. The relevant parts of build pipeline in this case 
>>> is:
>>>
>>> BuildFlow project A (scheduled by the logged in user) --> Build Flow 
>>> project B --> Free Style Project with an Editable Email Notification post 
>>> build step.
>>>
>>> Thanks in advance, 
>>>
>>> Stuart
>>>
>>  -- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "Jenkins Users" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/jenkinsci-users/nQtro7RisO4/unsubscribe
>> .
>> To unsubscribe from this group and all its topics, send an email to 
>> jenkinsci-use...@googlegroups.com <javascript:>.
>> 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 jenkinsci-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to