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

PROPFILE handling of missing file isn't very nice

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • token-macro-plugin
    • None
    • Jenkins 1.460
      build-name-setter 1.3
      token macro plugin 1.5.1

      My build generates a properties file containing version information (derived from various things like the subverison revision and branch name). I'd like to be able to include this in my build names automatically. I'm looking at setting the build name to something like this:

      #${BUILD_NUMBER} - ${PROPFILE,file="version.properties",property="version"}

      Since build-name-setting runs twice (once after checkout and once after build), the first attempt fails as the properties file doesn't exist yet.

      In the case when I try to use an invalid macro, an message is logged in the console output ("Unrecognized macro 'XXX' in ....") but the build otherwise continues. However, in this case, a FATAL error is logged:

      FATAL: /home/jenkins/.jenkins/jobs/..../version.properties (No such file or directory)
      java.io.FileNotFoundException: /home/jenkins/.jenkins/jobs/..../version.properties (No such file or directory)
      <rest of stack trace>

      It would be nice if the behaviour was consistent, and the absence of the properties file simply resulted in a warning similar to an invalid macro, rather than completely breaking the build.

          [JENKINS-13509] PROPFILE handling of missing file isn't very nice

          Chris Holman added a comment -

          I fixed this locally using an additional catch statement in org.jenkinsci.plugins.buildnamesetter.BuildNameSetter.setDisplayName(...):

              private void setDisplayName(AbstractBuild build, BuildListener listener) throws IOException, InterruptedException {
                  try {
                      build.setDisplayName(TokenMacro.expand(build, listener, template));
                  } catch (MacroEvaluationException e) {
                      listener.getLogger().println(e.getMessage());
                  } catch (FileNotFoundException fnfe) {
                      listener.getLogger().println(fnfe.getMessage());
                  }
              }
          

          Chris Holman added a comment - I fixed this locally using an additional catch statement in org.jenkinsci.plugins.buildnamesetter.BuildNameSetter.setDisplayName(...): private void setDisplayName(AbstractBuild build, BuildListener listener) throws IOException, InterruptedException { try { build.setDisplayName(TokenMacro.expand(build, listener, template)); } catch (MacroEvaluationException e) { listener.getLogger().println(e.getMessage()); } catch (FileNotFoundException fnfe) { listener.getLogger().println(fnfe.getMessage()); } }

          Or create an empty file at that (/home/jenkins/.jenkins/jobs/..../version.properties) location, so that it can find a file, but not able to get a property out of it.

          Florin Hillebrand added a comment - Or create an empty file at that (/home/jenkins/.jenkins/jobs/..../version.properties) location, so that it can find a file, but not able to get a property out of it.

          Alex Earl added a comment -

          This was fixed some time ago, I think in token macro 1.8

          Alex Earl added a comment - This was fixed some time ago, I think in token macro 1.8

            slide_o_mix Alex Earl
            pmilliken Paul Milliken
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: