3

I have been modifying the default groovy template that the Email Ext plugin supplies.

Firstly, I had to modify the JUnitTestResult and need to format it accordingly to my need. I found in the it.JUnitTestResult, it is a reference to the ScriptContentBuildWrapper class. And then I was able to format the JUnitTestResult according to my need.

Now I am facing a second difficulty:

  • Along with those contents, I need to append more content from a file that resides in the job workspace. How to access the files that reside in the workspace directory.

I would be interested to know how I can access the build context object. Whats the java class name and things like that.

Josh Unger
  • 6,717
  • 6
  • 33
  • 55
Exploring
  • 2,493
  • 11
  • 56
  • 97

3 Answers3

0

Just use build which returns an AbstractBuild

Try -

build.workspace

Which returns the FilePath of the directory where the build is being built.

See AbstractBuild.getWorkspace.

Tip: in Groovy, you can avoid the "get" and use field-like access notation.

Josh Unger
  • 6,717
  • 6
  • 33
  • 55
0

Depending on which version of email-ext you are using, you can use the tokens provided to get access to things, so if you look at the token help, you'll see lots of tokens. These can be used in the groovy templates to do the same thing. For instance, the FILE token can be used in the Groovy by doing FILE(path: 'path/to/file') and it will replace with the contents of the file (only works on files that are below the workspace).

slide
  • 792
  • 7
  • 9
0

The build object is not available directly in all groovy scripts (e.g. groovy build script, groovy system build script, groovy post-build script, groovy script as evaluated in email-ext). The most portable way of obtaining build object in groovy script for a running build is:

import hudson.model.*
def build = Thread.currentThread().executable

Then you can get workspace and access files inside like this:

workspace = build.getEnvVars()["WORKSPACE"]
afilename = workspace + "/myfile"
afile = new File(afilename);
// afile.write "write new file"
// afile << "append to file"
// def lines = afile.readLines()
gaoithe
  • 4,218
  • 3
  • 30
  • 38