Quantcast

Accessing file on slave node from email-ext script (groovy)

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Accessing file on slave node from email-ext script (groovy)

Bryan Hunt
New subscriber here...

I have searched through the archives looking for an answer but haven't yet been able to find a solution to my problem (even though it appears this question has been asked before)

I have specific build output that I need to load into my email-ext script (a specially formatted version string) so I have the following code in the start of my groovy script which works fine if everything is executed from the master but fails otherwise

<% def versionString = ""
fr = new FileReader(build.workspace.toString() + "\\Build\\version.txt")
if (fr != null) {
versionString = fr.readLine()
} %>

Produces the following error:
        Exception: javax.script.ScriptException: java.io.FileNotFoundException: c:\jenkins\workspace\project_name\Build\version.txt (No such file or directory)

So aside from the obvious need for a try/catch block does anyone have a recommendation for loading a file from a slave?

Regards,
Bryan H.

P.S. Is there a way to change the MimeMessage.subject from inside the groovy body script (or do I have to ask my administrator to kindly update the plugin to a version > 2.22)?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Accessing file on slave node from email-ext script (groovy)

slide
You probably want to look at the FilePath [1] documentation and use that in the script. As for modifying the subject, you will need to upgrade to >2.22 for that.

Thanks,

slide



On Mon, Oct 15, 2012 at 5:27 PM, Bryan Hunt <[hidden email]> wrote:
New subscriber here...

I have searched through the archives looking for an answer but haven't yet been able to find a solution to my problem (even though it appears this question has been asked before)

I have specific build output that I need to load into my email-ext script (a specially formatted version string) so I have the following code in the start of my groovy script which works fine if everything is executed from the master but fails otherwise

<% def versionString = ""
fr = new FileReader(build.workspace.toString() + "\\Build\\version.txt")
if (fr != null) {
versionString = fr.readLine()
} %>

Produces the following error:
        Exception: javax.script.ScriptException: java.io.FileNotFoundException: c:\jenkins\workspace\project_name\Build\version.txt (No such file or directory)

So aside from the obvious need for a try/catch block does anyone have a recommendation for loading a file from a slave?

Regards,
Bryan H.

P.S. Is there a way to change the MimeMessage.subject from inside the groovy body script (or do I have to ask my administrator to kindly update the plugin to a version > 2.22)?



--
Website: http://earl-of-code.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Accessing file on slave node from email-ext script (groovy)

Marek Gimza
Bryan,

FYI ...  have you tried to achieve the same result using JELLY scripting?

..
Mgimza

On Mon, Oct 15, 2012 at 8:48 PM, Slide <[hidden email]> wrote:
You probably want to look at the FilePath [1] documentation and use that in the script. As for modifying the subject, you will need to upgrade to >2.22 for that.

Thanks,

slide



On Mon, Oct 15, 2012 at 5:27 PM, Bryan Hunt <[hidden email]> wrote:
New subscriber here...

I have searched through the archives looking for an answer but haven't yet been able to find a solution to my problem (even though it appears this question has been asked before)

I have specific build output that I need to load into my email-ext script (a specially formatted version string) so I have the following code in the start of my groovy script which works fine if everything is executed from the master but fails otherwise

<% def versionString = ""
fr = new FileReader(build.workspace.toString() + "\\Build\\version.txt")
if (fr != null) {
versionString = fr.readLine()
} %>

Produces the following error:
        Exception: javax.script.ScriptException: java.io.FileNotFoundException: c:\jenkins\workspace\project_name\Build\version.txt (No such file or directory)

So aside from the obvious need for a try/catch block does anyone have a recommendation for loading a file from a slave?

Regards,
Bryan H.

P.S. Is there a way to change the MimeMessage.subject from inside the groovy body script (or do I have to ask my administrator to kindly update the plugin to a version > 2.22)?



--
Website: http://earl-of-code.com

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Accessing file on slave node from email-ext script (groovy)

Bryan Hunt
In reply to this post by slide
Thanks that is exactly what I needed. I ended up using the following:

<% def versionString = ""
def channel = null
if (build.workspace.isRemote())
{
channel = build.workspace.channel
}

fp = new hudson.FilePath(channel, build.workspace.toString() + "\\Build\\version.txt")
if (fp != null) {
versionString = fp.readToString()
} %>

Which appears to work well. I'm sure there is a much cleaner way of doing it (so if you have suggestions by all means send me an email).

As far as working around the outdated mod problem of modifying the subject I ended up having my build script dump my email subject and using ${BUILD_LOG_REGEX, regex="my_subject_regex", linesBefore=0, linesAfter=0, maxMatches=1, showTruncatedLines=false} in the email-ext subject line to pick it up thus accomplishing the same thing I was doing with a pre-send script.


On Monday, October 15, 2012 5:49:05 PM UTC-7, slide wrote:
You probably want to look at the FilePath [1] documentation and use that in the script. As for modifying the subject, you will need to upgrade to >2.22 for that.

Thanks,

slide



On Mon, Oct 15, 2012 at 5:27 PM, Bryan Hunt <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="JKEdKv7N_Y4J">brya...@...> wrote:
New subscriber here...

I have searched through the archives looking for an answer but haven't yet been able to find a solution to my problem (even though it appears this question has been asked before)

I have specific build output that I need to load into my email-ext script (a specially formatted version string) so I have the following code in the start of my groovy script which works fine if everything is executed from the master but fails otherwise

<% def versionString = ""
fr = new FileReader(build.workspace.toString() + "\\Build\\version.txt")
if (fr != null) {
versionString = fr.readLine()
} %>

Produces the following error:
        Exception: javax.script.ScriptException: java.io.FileNotFoundException: c:\jenkins\workspace\project_name\Build\version.txt (No such file or directory)

So aside from the obvious need for a try/catch block does anyone have a recommendation for loading a file from a slave?

Regards,
Bryan H.

P.S. Is there a way to change the MimeMessage.subject from inside the groovy body script (or do I have to ask my administrator to kindly update the plugin to a version > 2.22)?



--
Website: http://earl-of-code.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Accessing file on slave node from email-ext script (groovy)

Bryan Hunt
In reply to this post by Marek Gimza
Yes... It just really couldn't get jelly script to work to my satisfaction. Probably if I had more experience and better tools loaded my opinion might change but "JellyException: Could not parse Jelly script : null" isn't a particularly enlightening error.

On Tuesday, October 16, 2012 8:43:33 AM UTC-7, mgimza wrote:
Bryan,

FYI ...  have you tried to achieve the same result using JELLY scripting?

..
Mgimza

On Mon, Oct 15, 2012 at 8:48 PM, Slide <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="wPs0BIE_gREJ">slide...@...> wrote:
You probably want to look at the FilePath [1] documentation and use that in the script. As for modifying the subject, you will need to upgrade to >2.22 for that.

Thanks,

slide



On Mon, Oct 15, 2012 at 5:27 PM, Bryan Hunt <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="wPs0BIE_gREJ">brya...@...> wrote:
New subscriber here...

I have searched through the archives looking for an answer but haven't yet been able to find a solution to my problem (even though it appears this question has been asked before)

I have specific build output that I need to load into my email-ext script (a specially formatted version string) so I have the following code in the start of my groovy script which works fine if everything is executed from the master but fails otherwise

<% def versionString = ""
fr = new FileReader(build.workspace.toString() + "\\Build\\version.txt")
if (fr != null) {
versionString = fr.readLine()
} %>

Produces the following error:
        Exception: javax.script.ScriptException: java.io.FileNotFoundException: c:\jenkins\workspace\project_name\Build\version.txt (No such file or directory)

So aside from the obvious need for a try/catch block does anyone have a recommendation for loading a file from a slave?

Regards,
Bryan H.

P.S. Is there a way to change the MimeMessage.subject from inside the groovy body script (or do I have to ask my administrator to kindly update the plugin to a version > 2.22)?



--
Website: http://earl-of-code.com

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Accessing file on slave node from email-ext script (groovy)

Marek Gimza

Your right ..  I had to play around with the different jelly tags for it to work in a jelly script:
 
The best solution that works for me in a jelly script:
 
<h:parse html="MY_FILE.txt" var="rep_content"/>
       <br/>
<TABLE>
<TR><TD><PRE>${rep_content.asXML()}</PRE></TD></TR>
</TABLE>
 
FYI... the use of the <util:file and <util:loadText tags did not work for me at all ... I just kep getting a null value.
 
 
...
Mgimza
 

 
On Tue, Oct 16, 2012 at 8:47 PM, Bryan Hunt <[hidden email]> wrote:
Yes... It just really couldn't get jelly script to work to my satisfaction. Probably if I had more experience and better tools loaded my opinion might change but "JellyException: Could not parse Jelly script : null" isn't a particularly enlightening error.

On Tuesday, October 16, 2012 8:43:33 AM UTC-7, mgimza wrote:
Bryan,

FYI ...  have you tried to achieve the same result using JELLY scripting?

..
Mgimza

On Mon, Oct 15, 2012 at 8:48 PM, Slide <[hidden email]> wrote:
You probably want to look at the FilePath [1] documentation and use that in the script. As for modifying the subject, you will need to upgrade to >2.22 for that.

Thanks,

slide



On Mon, Oct 15, 2012 at 5:27 PM, Bryan Hunt <[hidden email]> wrote:
New subscriber here...

I have searched through the archives looking for an answer but haven't yet been able to find a solution to my problem (even though it appears this question has been asked before)

I have specific build output that I need to load into my email-ext script (a specially formatted version string) so I have the following code in the start of my groovy script which works fine if everything is executed from the master but fails otherwise

<% def versionString = ""
fr = new FileReader(build.workspace.toString() + "\\Build\\version.txt")
if (fr != null) {
versionString = fr.readLine()
} %>

Produces the following error:
        Exception: javax.script.ScriptException: java.io.FileNotFoundException: c:\jenkins\workspace\project_name\Build\version.txt (No such file or directory)

So aside from the obvious need for a try/catch block does anyone have a recommendation for loading a file from a slave?

Regards,
Bryan H.

P.S. Is there a way to change the MimeMessage.subject from inside the groovy body script (or do I have to ask my administrator to kindly update the plugin to a version > 2.22)?



--
Website: http://earl-of-code.com


Loading...