It has a logger, not a listener: binding.put("logger",
listener.getLogger());


If you need to get environment variables you can do it like this ENV(var:
'NAME_OF_VAR'). Any token-macro token can be used in this way.

On Thu, Oct 15, 2015 at 8:03 AM Philippe Payant <[email protected]>
wrote:

> I am so close now!
>
> Here is my problem.  My script (now a file in email-templates) starts with:
>
> def env = build.getEnvironment(listener)
>
> I placed this in the Default Subject of my project:
>
> ${SCRIPT, script="subject.groovy"}
>
> The email I get is a Groovy error message:
>
> Error in script or template: groovy.lang.MissingPropertyException: No such
> property: listener for class: Script1
>
> Weird, the URL for the bootstrap variables you included clearly shows that
> 'listener' should be there. What's up?
>
>
> On Thursday, October 15, 2015 at 5:45:28 AM UTC-4, slide wrote:
>
>> See comments inline
>>
>>
>> On Wed, Oct 14, 2015 at 1:08 PM Philippe Payant <[email protected]>
>> wrote:
>>
>>> Yes, I see this is another alternative, and it is even simpler than a
>>> pre-send script.  I would like to do that.
>>>
>>> Can you clarify some details for me?
>>>
>>> 1. Seems obvious from the doc that get-commit-info.groovy can/should be
>>> placed in JENKINS_HOME/email-templates right?
>>>
>>
>> Yes, this is correct. You can also install the config file provider
>> plugin and put the script in there, then you would do 'managed:name of
>> script' instead of the filename.
>>
>>
>>
>>> 2. What are the 'bootstrap' variables (the ones like 'build' and 'msg'
>>> for pre-send scripts and 'manager' for groovy post-build script) ?
>>>
>>
>> You can see the list here:
>> https://github.com/jenkinsci/email-ext-plugin/blob/master/src/main/java/hudson/plugins/emailext/plugins/content/ScriptContent.java#L118-L122
>>
>>
>>> 3. How is the result of that script to be returned?  The help for this
>>> says "only the last value in the script will be used in the
>>> expansion".  What does that mean?
>>>
>>
>> This means that the result of the last line in the script is what is used
>> to replace the token. ${SCRIPT, script='foo.groovy'} would be replaced by
>> the result of the last line of foo.groovy.
>>
>>
>
>>> I will google for an example.
>>>
>>> On Wednesday, October 14, 2015 at 3:56:33 PM UTC-4, slide wrote:
>>>
>>>> I mean for you to change the Subject field in the email-ext
>>>> configuration to have something like ${SCRIPT,
>>>> script='get-commit-info.groovy'}, then you would have a groovy script that
>>>> grabbed the info and returned it as a string. Email-ext would then take
>>>> care of putting the correct text in. You don't need to do it via a pre-send
>>>> script.
>>>>
>>>> On Wed, Oct 14, 2015 at 12:31 PM Philippe Payant <[email protected]>
>>>> wrote:
>>>>
>>> Your suggestion launched me on a track that worked.  But I got it all
>>>>> wrong because I did not understand all I could do with a groovy script.
>>>>>
>>>>> I upgraded my build script (Python based and commited in the sources)
>>>>> to use SVN_URL & SVN_REVISION to pull the commit log from Subversion.  The
>>>>> build script then parses the commit log to find the bug number.  The bug
>>>>> number is printed to stdout and it ends up in the Jenkins build log.
>>>>>
>>>>> Then I wrote a pre-send groovy script for email-ext to grep the build
>>>>> log for the build number.  Once I have the build number, the email subject
>>>>> is updated.  Here is my script:
>>>>>
>>>>> --snip--
>>>>> import java.util.regex.Pattern;
>>>>> import java.util.regex.Matcher;
>>>>> try {
>>>>>   log = build.getLog()
>>>>>   def pattern =
>>>>> Pattern.compile(/7928DEC7-17B5-40a1-B094-282AE167178F\s+(\S+)\s+(.*)/)
>>>>>   def matcher = pattern.matcher(log)
>>>>>   def found = matcher.find()
>>>>>   if ( found ) {
>>>>>     def job = build.getParent().name
>>>>>     def number = matcher.group(1)
>>>>>     def summary = matcher.group(2)
>>>>>     def subject = summary
>>>>>     if ( number != 'N/A' ) {
>>>>>       subject = "${summary} (bug ${number})"
>>>>>     }
>>>>>     msg.setSubject("[Build ${job}] ${subject}")
>>>>>   }
>>>>> } catch(e) {
>>>>>   msg.setContent(e.toString(),'text/plain')
>>>>> }
>>>>> --end snip--
>>>>>
>>>>> For people who are new to this, some pseudo-code and explanations:
>>>>>
>>>>> The 'build' and 'msg' objects are prepopulated when the script is
>>>>> launched.  We get the log from 'build'.  Then we use a
>>>>> java.util.regex.Matcher to locate the build number in the log text.
>>>>> Finally, the 'msg' object (a plain Java MimeMessage object) is modified
>>>>> with a new subject.
>>>>>
>>>>> This is crazy.  Now my build script (commited along the sources) is
>>>>> performing a task it should not care about: parsing a SVN commit.  The
>>>>> better solution would be to have the pre-send groovy script do all that.
>>>>> It has access to SVN_URL and SVN_REVISION.  My preferred language for my
>>>>> build system is Python, so I would probably shell out to an external 
>>>>> Python
>>>>> script to parse the commit and contact Bugzilla for the summary.
>>>>>
>>>>> I got some help from these:
>>>>>
>>>>> https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin#Email-extplugin-PresendScript
>>>>>
>>>>> https://www.cloudbees.com/jenkins/juc-2015/presentations/JUC-2015-USEast-Groovy-With-Jenkins-McCollum.pdf
>>>>> https://wiki.jenkins-ci.org/display/JENKINS/Groovy+Postbuild+Plugin
>>>>> http://www.groovy-lang.org/single-page-documentation.html
>>>>> http://javadoc.jenkins-ci.org/
>>>>>
>>>>> On Tuesday, October 13, 2015 at 11:07:55 AM UTC-4, slide wrote:
>>>>>
>>>>>> Are you using email-ext or Mailer? If using email-ext, you could use
>>>>>> a SCRIPT token and have a groovy script that grabs anything you want from
>>>>>> the build.
>>>>>>
>>>>>> On Tue, Oct 13, 2015 at 7:55 AM Philippe Payant <[email protected]>
>>>>>> wrote:
>>>>>>
>>>>> Given that a Subversion comment  contains a Bugzilla bug number, for
>>>>>>> example:
>>>>>>>
>>>>>>> Fix Hoopla bug in the "easy" mode.  Bug 9413
>>>>>>>
>>>>>>> I would like the "build succesful" email to be something like:
>>>>>>>
>>>>>>> "MyProduct: build successful - bug 9413"
>>>>>>>
>>>>>>> For bonus points, I would actually like the subject to contain the
>>>>>>> Bugzilla summary of bug 9413:
>>>>>>>
>>>>>>> "MyProduct: build successful - bug 'Hoopla display is wrong in easy
>>>>>>> mode' "
>>>>>>>
>>>>>>>
>>>>>>> -- Philippe
>>>>>>>
>>>>>>> --
>>>>>>> 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/6aad9b4a-de29-4d0a-9879-6136dd055302%40googlegroups.com
>>>>>>> <https://groups.google.com/d/msgid/jenkinsci-users/6aad9b4a-de29-4d0a-9879-6136dd055302%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/c62636ec-0d9d-4b65-9bf5-42291eb251cb%40googlegroups.com
>>>>> <https://groups.google.com/d/msgid/jenkinsci-users/c62636ec-0d9d-4b65-9bf5-42291eb251cb%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/7f063452-9027-41c5-b9ee-53f94429d465%40googlegroups.com
>>> <https://groups.google.com/d/msgid/jenkinsci-users/7f063452-9027-41c5-b9ee-53f94429d465%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/36ece3dc-404c-4954-8a20-b3401990ad65%40googlegroups.com
> <https://groups.google.com/d/msgid/jenkinsci-users/36ece3dc-404c-4954-8a20-b3401990ad65%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/CAPiUgVcWvZc%3DGCzbmS15tRNq16QN-PcxB5xgV%3DGBxkoTGhhU0g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to