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

Upgrading from 1.646 to 1.651.3 breaks creating parameters from Groovy

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Critical Critical
    • core
    • None
    • Jenkins running on Windows 10

      I have a script to build an installer that using Groovy uses regex to read a string from one file, stores it as an environment variable and then uses this to fill gaps in another file.

      In 1.646 this worked, but it is failing in 1.651.3 saying that the parameter is null in the second script. Both scripts are executed using Execute System Groovy Script. Downgrading back to 1.646 makes the scripts work again.

      The first script:
      import hudson.FilePath;
      import hudson.model.*

      // Read VersionString and CopyrightString into EnvVars from VersionInfo file

      if(build.workspace.isRemote())
      {
      channel = build.workspace.channel;
      file = new FilePath(channel, build.workspace.toString() + "/te/VersionInfo.rc")
      } else {
      file = new FilePath(new File(build.workspace.toString() + "/te/VersionInfo.rc"))
      }
      fileText = file.readToString();

      CopyrightStr = ( fileText =~ /"LegalCopyright"."(.)
      0/)[0][1];
      VerStr = ( fileText =~ /CONST_VERSION_PERIOD."(.)
      0/)[0][1];

      def build = Thread.currentThread().executable
      def pa = new ParametersAction([
      new StringParameterValue("Version_String", VerStr),
      ])
      build.addAction(pa)

      Second script:
      import hudson.FilePath;
      import java.util.regex.Matcher
      // Update defines in the InnoSetup script
      def VerString = build.envVars["Version_String"]
      def TEFilePath = build.envVars["TE_Exe"]
      def MasterViewReset = build.envVars["MasterViewReset"] ? -1 : 0
      def ViewLayoutReset = build.envVars["ViewLayoutReset"] ? -1 : 0
      def TERegistryReset = build.envVars["TERegistryReset"] ? -1 : 0

      println("Updating Inno script:")
      println("VerString = "+ VerString)

      if(build.workspace.isRemote())
      {
      channel = build.workspace.channel;
      file = new FilePath(channel, build.workspace.toString() + "/Installer/Script/TESetupScript.iss")
      } else {
      file = new FilePath(new File(build.workspace.toString() + "/Installer/Script/TESetupScript.iss"))
      }

      fileText = file.readToString();

      // replace the defines in the script with the parameters
      fileText = fileText.replaceFirst(/#define MyAppVersion .*/, '#define MyAppVersion "'Matcher.quoteReplacement(VerString)'"')
      fileText = fileText.replaceFirst(/#define TEExeFilePath .*/, '#define TEExeFilePath "'Matcher.quoteReplacement(TEFilePath)'"')
      fileText = fileText.replaceFirst(/#define MyCopyrightNotice .*/, '#define MyCopyrightNotice "© 1997-' + Calendar.instance.format("yyyy") + ' Basis Technologies International Limited"')
      fileText = fileText.replaceFirst(/#define NeedMasterViewReset .*/, '#define NeedMasterViewReset "'MasterViewReset'"')
      fileText = fileText.replaceFirst(/#define NeedViewLayoutReset .*/, '#define NeedViewLayoutReset "'ViewLayoutReset'"')
      fileText = fileText.replaceFirst(/#define NeedTERegistryReset .*/, '#define NeedTERegistryReset "'TERegistryReset'"')

      file.write(fileText, null);

      I'll attach an example VersionInfo.rc file.

      I can see in the build logs that the println("VerString = "+ VerString) line is outputting VerString as null. The log output also references a Nullpointer exception from quoteReplacement(VerString) in the 2nd script which backs up the 2nd script not being able to find the environment variable.

            Unassigned Unassigned
            mallwood1 Matt Allwood
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: