Hi Vincent,
I think the first step to convert that kind of thing is probably to
externalize it in a @NonCPS function to avoid potential issues while
refactoring.
Also, probably disable temporarily sandbox while converting it.
There's access to the raw build from the wrapped one (currentBuild.rawBuild
or so IIRC).

My 2 cents

Le 6 févr. 2017 2:52 PM, "Vincent Massol" <vmas...@gmail.com> a écrit :

> Thanks Richard,
>
> That looks a bit expensive though since all I need is to find the test
> results for the **current** job only. I wonder if there isn’t a simpler way.
>
> Thanks
> -Vincent
>
> > On 6 Feb 2017, at 14:39, Richard Ginga <rgi...@disruptorbeam.com> wrote:
> >
> > ok, if you need to step through to build object, I use this code to
> eventually get the log of some other other job:
> >
> > for (item in Jenkins.instance.getAllItems()) {
> >       //
> >       // find the correct job
> >       //
> >       if (item.getFullName() == SERVER_BUILD_NAME) {
> >         def job = item.getAllJobs()
> >         //
> >         // get the last successful build object
> >         //
> >         def build = job[0].getLastSuccessfulBuild()
> >         //
> >         // get the build log from that build
> >         //
> >         def log = build.getLog(300)
> >
> >
> > On Mon, Feb 6, 2017 at 8:34 AM, Vincent Massol <vmas...@gmail.com>
> wrote:
> > Hi Richard,
> >
> > > On 6 Feb 2017, at 14:31, Richard Ginga <rgi...@disruptorbeam.com>
> wrote:
> > >
> > > Vincent, I am not a Jenkins master, but, you need to replace the
> "manager" variable. that is defined by groovy-postbuild. I "think" all you
> need is to use "currentBuild" as the variable to access build methods and
> "Jenkins.instance." to access FilePath.
> >
> > I’ve tried to use currentBuild but it’s wrapped and only offers a few
> methods. For example it doesn’t allow calling getWorkspace() nor
> getTestResultAction().
> >
> > So right now I’m trying to find a way to get access to a
> https://github.com/jenkinsci/junit-plugin/blob/master/src/
> main/java/hudson/tasks/junit/TestResultAction.java instance.
> >
> > (Previously it was manager.build.testResultAction)
> >
> > Thanks
> > -Vincent
> >
> > > On Mon, Feb 6, 2017 at 3:25 AM, Vincent Massol <vmas...@gmail.com>
> wrote:
> > > Hi Jenkins masters,
> > >
> > > I had a groovy postbuild script that I'm trying to migrate to pipeline
> groovy.
> > >
> > > It's setting the description of failed test (in order to embed the
> screenshot taken by our selenium tests in the jenkins failed test UI - For
> example: http://ci.xwiki.org/job/xwiki-enterprise-test-ui-7.4.x/org.
> xwiki.enterprise$xwiki-enterprise-test-ui/350/testReport/junit/org.xwiki.
> test.ui.appwithinminutes/WizardTest/testCreateApplication/ ).
> > >
> > > I've googled a lot but couldn't find any starting point to convert
> this script:
> > >
> > >  /**
> > >    * This script attaches the screenshot of a failing Selenium test to
> the failed test's description.
> > >    * The screenshot is preserved after the workspace gets cleared by a
> new build.
> > >    */
> > >   def attachScreenshotToFailingTests() {
> > >     def channel = manager.build.workspace.channel;
> > >     def workspace = manager.build.workspace.toString();
> > >
> > >     def testResults = manager.build.testResultAction;
> > >     if (testResults == null) {
> > >       // No tests were run in this build, nothing left to do.
> > >       return;
> > >     }
> > >
> > >     // Go through each failed test in the current build.
> > >     def failedTests = testResults.getFailedTests();
> > >     for (def failedTest : failedTests) {
> > >       // Compute the test's screenshot file name.
> > >       def testClass = failedTest.getClassName();
> > >       def testSimpleClass = failedTest.getSimpleName();
> > >       def testExample = failedTest.getName();
> > >
> > >       def suiteResultFile = failedTest.getSuiteResult().getFile();
> > >       if (suiteResultFile == null) {
> > >         // No results available. Go to the next test.
> > >         continue;
> > >       }
> > >
> > >       // Compute the screenshot's location on the build agent.
> > >       def targetFolderPath = new hudson.FilePath(channel,
> suiteResultFile).getParent().getParent();
> > >       // The screenshot can have 2 possible file names and locations,
> we have to look for both.
> > >       // Selenium 1 test screenshots.
> > >       def imageAbsolutePath1 = new hudson.FilePath(targetFolderPath,
> "selenium-screenshots/${testClass}-${testExample}.png");
> > >       // Selenium 2 test screenshots.
> > >       def imageAbsolutePath2 = new hudson.FilePath(targetFolderPath,
> "screenshots/${testSimpleClass}-${testExample}.png");
> > >       // Determine which one exists, if any.
> > >       def imageAbsolutePath = imageAbsolutePath1.exists() ?
> imageAbsolutePath1 : (imageAbsolutePath2.exists() ? imageAbsolutePath2 :
> null);
> > >
> > >       // If the screenshot exists...
> > >       if (imageAbsolutePath != null) {
> > >         // Build a base64 string of the image's content.
> > >         def imageDataStream = imageAbsolutePath.read();
> > >         byte[] imageData = IOUtils.toByteArray(imageDataStream);
> > >         def imageDataString = "data:image/png;base64," +
> DatatypeConverter.printBase64Binary(imageData);
> > >
> > >         def testResultAction = failedTest.getParentAction();
> > >         def testResult = testResultAction.getResult();
> > >
> > >         // Build a description HTML to be set for the failing test
> that includes the image in Data URI format.
> > >         def description = "<h3>Screenshot</h3>";
> > >         description += "<a href=\"" + imageDataString + "\"><img
> style=\"width: 800px\" src=\"" + imageDataString + "\" /></a>";
> > >
> > >         // Set the description to the failing test and save it to disk.
> > >         testResultAction.setDescription(failedTest, description);
> > >         // Note: the owner field is marked as deprecated and it might
> go away. It should be replaced by an instance of Run in the future,
> > >         // but FTM, I do not know how to access it. For the future, in
> case descriptions start not getting stored, this might cause it.
> > >         testResultAction.owner.save();
> > >       }
> > >     }
> > >   }
> > >
> > > Any pointer would be much appreciated.
> > >
> > > Thanks
> > > -Vincent
> > >
> > >
> > >
> > > --
> > > 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.
> > > To view this discussion on the web visit https://groups.google.com/d/
> msgid/jenkinsci-users/15ee3c93-8849-492a-8355-3b2e11c05ada%40googlegroups.
> com.
> > > For more options, visit https://groups.google.com/d/optout.
> > >
> > >
> > >
> > > --
> > > Dick Ginga
> > > Build Engineer
> > > rgi...@disruptorbeam.com
> > >
> > >
> > > --
> > > 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/IJYJx6hXhBc/unsubscribe.
> > > To unsubscribe from this group and all its topics, send an email to
> jenkinsci-users+unsubscr...@googlegroups.com.
> > > To view this discussion on the web visit https://groups.google.com/d/
> msgid/jenkinsci-users/CAL3PpaUykt14Nrg1GuhYqy7H0Aaq%
> 3D4QL42YO3%2B%3DQZq--%2B4H4iA%40mail.gmail.com.
> > > 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.
> > To view this discussion on the web visit https://groups.google.com/d/
> msgid/jenkinsci-users/D35787B8-4085-4EDA-94CE-BBE145D577CA%40gmail.com.
> > For more options, visit https://groups.google.com/d/optout.
> >
> >
> >
> > --
> > Dick Ginga
> > Build Engineer
> > rgi...@disruptorbeam.com
> >
> >
> > --
> > 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/IJYJx6hXhBc/unsubscribe.
> > To unsubscribe from this group and all its topics, send an email to
> jenkinsci-users+unsubscr...@googlegroups.com.
> > To view this discussion on the web visit https://groups.google.com/d/
> msgid/jenkinsci-users/CAL3PpaWcZqJeHQ%2B5eGWid4KHM1QYUxT66Vzwx9C0o4Z
> JgvVgmg%40mail.gmail.com.
> > 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.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/jenkinsci-users/D55E2C5F-29A8-4654-B984-A7079262D6FB%40gmail.com.
> 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/CANWgJS4-sm7S0YVTOpYUEWuLs4vbC-xq21zCMpneX6Qzq%2ButxQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to