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

Ant plugin does not correctly resolve and property resolving empty build parameter

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Component/s: ant-plugin
    • Labels:
      None
    • Environment:
      Jenkins: 2.43
      Ant Plugin: 1.4

      OS: Mac/Linux/Windows - though problems most pronounced on windows
    • Similar Issues:

      Description

      If an ant build passes through a parameter referencing a "build parameter", the replacement will not occur if the build parameter is an empty string.

      e.g. if properties on Ant build step are:

      myprop=$buildVariable

      The resulting ant command line will look like:

      ant -Dmyprop=$buildVariable

      instead of

      ant -Dmyprop=

      The reason is that the EnvVars jenkins class, will remove properties when they are empty. This odd behaviour is also discussed in JENKINS-15146 ... it would seem that empty string is valid and only null should be removed.

      This issue is particularly tricky as things will mostly work as expected on Unix operating systems because the $buildVariable will be replaced by the shell with the build variable in the environment. If fails completely on Windows because no variable expansion occurs.

      Also note that the same behaviour is not seen by the gradle plugin, as does these replacements slightly differently (replacing build parameters without putting them into EnvVars).

      I'm preparing a pull request to resolve this.

        Attachments

          Activity

          Hide
          mattdoran Matt Doran added a comment -

          Any movement?   Here's the PR I submitted way back ... solves the problem for us:

           

          https://github.com/jenkinsci/ant-plugin/pull/25

          Show
          mattdoran Matt Doran added a comment - Any movement?   Here's the PR I submitted way back ... solves the problem for us:   https://github.com/jenkinsci/ant-plugin/pull/25
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Matt Doran
          Path:
          src/main/java/hudson/tasks/Ant.java
          src/test/java/hudson/tasks/AntTest.java
          http://jenkins-ci.org/commit/ant-plugin/c57e18f6ac9c01ccce927930aed0221853d38ff6
          Log:
          JENKINS-41801: Allow empty build parameters to be replaced in ant properties.

          By using EnvVars.overrideAll() to add all build variable to EnvVars, any blank ("") build parameters are not added (or if they existed would be removed) from EnvVars. This means any reference to a blank variable is not replaced instead of being set to empty.

          The tests check the log line where the ant command line is printed. It's needed to check here for reliable tests, because on unix the $parameter will be replaced by the shell, but not in windows. By testing the command line params we ensure the replacements occur before going to the OS to run ant.

          The tests try to be resilient to the command line and param formatting on windows.

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Matt Doran Path: src/main/java/hudson/tasks/Ant.java src/test/java/hudson/tasks/AntTest.java http://jenkins-ci.org/commit/ant-plugin/c57e18f6ac9c01ccce927930aed0221853d38ff6 Log: JENKINS-41801 : Allow empty build parameters to be replaced in ant properties. By using EnvVars.overrideAll() to add all build variable to EnvVars, any blank ("") build parameters are not added (or if they existed would be removed) from EnvVars. This means any reference to a blank variable is not replaced instead of being set to empty. The tests check the log line where the ant command line is printed. It's needed to check here for reliable tests, because on unix the $parameter will be replaced by the shell, but not in windows. By testing the command line params we ensure the replacements occur before going to the OS to run ant. The tests try to be resilient to the command line and param formatting on windows.
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Armando Fernández
          Path:
          src/main/java/hudson/tasks/Ant.java
          src/test/java/hudson/tasks/AntTest.java
          http://jenkins-ci.org/commit/ant-plugin/7025e65f06ee3934db303960a74846cc52440a26
          Log:
          Merge pull request #25 from mattdoran/master

          JENKINS-41801: Allow empty build parameters to be replaced in ant properties

          Compare: https://github.com/jenkinsci/ant-plugin/compare/d1c5e13f88ac...7025e65f06ee

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Armando Fernández Path: src/main/java/hudson/tasks/Ant.java src/test/java/hudson/tasks/AntTest.java http://jenkins-ci.org/commit/ant-plugin/7025e65f06ee3934db303960a74846cc52440a26 Log: Merge pull request #25 from mattdoran/master JENKINS-41801 : Allow empty build parameters to be replaced in ant properties Compare: https://github.com/jenkinsci/ant-plugin/compare/d1c5e13f88ac...7025e65f06ee
          Hide
          armfergom Armando Fernandez added a comment -

          Thanks for your contribution. I will now merge this and will proceed to cut a new release.

          Show
          armfergom Armando Fernandez added a comment - Thanks for your contribution. I will now merge this and will proceed to cut a new release.
          Hide
          armfergom Armando Fernandez added a comment -

          A new version has been published: 1.5. Should be available soon.

          Show
          armfergom Armando Fernandez added a comment - A new version has been published: 1.5. Should be available soon.

            People

            • Assignee:
              armfergom Armando Fernandez
              Reporter:
              mattdoran Matt Doran
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: