Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-47761

Unable to view parameters created in post build to pass them as part of promote build plugin

    XMLWordPrintable

Details

    Description

      Hi,

      I am trying to capture few values from the output window using Groovy script - Regular expressions. I have observed that the captured value is not being saved into newly created string parameter. Please find below the grrovy script which was used.

      Jenkins version - 2.73.2

      Promoted Build plugin version - 2.31

       

      I have gone through few blogs and its been suggested to change system properties with the below statment but I am getting an error while running the same.

      hudson.model.ParametersAction.safeParameters to a comma-separated list of safe parameter names

       

      import hudson.model.*

      def matcher = manager.getLogMatcher('setting scenario result folder to (.*)LRR$')

      if (matcher.matches()) {
      resDir=matcher.group(1)
      manager.build.addAction(
      new ParametersAction([
      new StringParameterValue("RES_DIR", "${resDir}")
      ])
      )
      }

      manager.listener.logger.println "${resDir}"
      manager.listener.logger.println "$RES_DIR" - getting error for this statement
      matcher = manager.getLogMatcher('DATE.*)$')

      if (matcher.matches()) {
      buildDate=matcher.group(1)
      manager.build.addAction(
      new ParametersAction([
      new StringParameterValue("RES_TIMESTAMP", "${buildDate}")
      ])
      )
      }

      manager.listener.logger.println("Hello 1");
      manager.listener.logger.println "$RES_TIMESTAMP";- getting error for this statement

      Attachments

        Activity

          amith_arangi Amith Arangi added a comment -

          Groovy script failed:

          groovy.lang.MissingPropertyException: No such property: RES_DIR for class: Script1 at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53) at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:52) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307) at Script1.run(Script1.groovy:19) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:585) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:623) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:594) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript.evaluate(SecureGroovyScript.java:170) at org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder.perform(GroovyPostbuildRecorder.java:362) at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20) at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:736) at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:682) at hudson.model.Build$BuildExecution.post2(Build.java:186) at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:627) at hudson.model.Run.execute(Run.java:1762) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:421)

          amith_arangi Amith Arangi added a comment - Groovy script failed: groovy.lang.MissingPropertyException: No such property: RES_DIR for class: Script1 at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53) at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:52) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307) at Script1.run(Script1.groovy:19) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:585) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:623) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:594) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript.evaluate(SecureGroovyScript.java:170) at org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder.perform(GroovyPostbuildRecorder.java:362) at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20) at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:736) at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:682) at hudson.model.Build$BuildExecution.post2(Build.java:186) at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:627) at hudson.model.Run.execute(Run.java:1762) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:421)
          oleg_nenashev Oleg Nenashev added a comment -

          I doubt there is anything to be done on the Promoted builds side. I would start from checking how Groovy PostBuild plugin maps the environment veriables

          oleg_nenashev Oleg Nenashev added a comment - I doubt there is anything to be done on the Promoted builds side. I would start from checking how Groovy PostBuild plugin maps the environment veriables
          ikedam ikedam added a comment -

          I can't get the point or what you expect at all.

          The groovy interpolation ("$RES_DIR ...") works for the groovy variables, not for the build parameters.
          So your code should never work.
          And it looks to me that you already succeeded to capture and display outputs with manager.listener.logger.println "${resDir}".

          Please reopen the ticket if you missed explaining the actual point.

          ikedam ikedam added a comment - I can't get the point or what you expect at all. The groovy interpolation ("$RES_DIR ...") works for the groovy variables, not for the build parameters. So your code should never work. And it looks to me that you already succeeded to capture and display outputs with manager.listener.logger.println "${resDir}" . Please reopen the ticket if you missed explaining the actual point.

          People

            amith_arangi Amith Arangi
            amith_arangi Amith Arangi
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: