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

withMaven prints debug log and pollutes

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Fixed
    • Component/s: pipeline-maven-plugin
    • Labels:
      None
    • Environment:
      Jenkins 2.60.3
      Pipeline Maven Integration 2.0.1
      mvn 3.5.3
    • Similar Issues:
    • Released As:
      pipeline-maven 3.10.0

      Description

      Expected behavior:

      In pipeline:

       

      withMaven(
       maven: mvnId, // Maven installation declared in the Jenkins "Global Tool Configuration"
       mavenSettingsConfig: mvnSettingsId, // Maven settings.xml file defined with the Jenkins Config File Provider Plugin
       mavenLocalRepo: mavenLocalRepo
       )
      { 
         result = sh( 
            returnStdout: true, 
            script: 'mvn org.apache.maven.plugins:maven-help-plugin::evaluate -Dexpression=project.version -q -DforceStdout -B" ) 
      }
      

       

      Desired result variable value:

      1.5.0

       

      Actual result variable:

      ----- withMaven Wrapper script -----
       Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T19:49:05Z)
       Maven home: /var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/mvn-3.5.3
       Java version: 1.8.0_161, vendor: Oracle Corporation
       Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre
       Default locale: en_US, platform encoding: UTF-8
       OS name: "linux", version: "3.10.0-693.17.1.el7.x86_64", arch: "amd64", family: "unix"
       1.5.0

      Analysis:

      withMaven wrapper adds stdout info, that cannot be removed, disabled, according to source:

      https://github.com/jenkinsci/pipeline-maven-plugin/blob/b150161c91769de782af6c5b2ebe7907a4bd17b0/jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/WithMavenStepExecution2.java

      However, that breaks the way we gets output with mvn command.

      Workaround: specifically to maven-help-plugin, I can redirect output to a file, and readFile that.

      Long-term solution (exclusive choice):

      1. add a silent field to withMaven, to disable any output?
      2. add a showDebug field to show debug info
      3. do not show debug info, except when mvn command fails

      Thank you.

        Attachments

          Activity

          antoinetran Antoine Tran created issue -
          antoinetran Antoine Tran made changes -
          Field Original Value New Value
          Description Expected behavior:

          In pipeline:

          withMaven(
           maven: mvnId, // Maven installation declared in the Jenkins "Global Tool Configuration"
           mavenSettingsConfig: mvnSettingsId, // Maven settings.xml file defined with the Jenkins Config File Provider Plugin
           mavenLocalRepo: mavenLocalRepo
           ) {
           result = sh(
           returnStdout: true,
           script: 'mvn org.apache.maven.plugins:maven-help-plugin::evaluate -Dexpression=project.version -q -DforceStdout -B"
           )
           }

          result variable value is "1.5.0"

          Actual behavior:

          result variable is:

          "----- withMaven Wrapper script -----
          Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T19:49:05Z)
          Maven home: /var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/mvn-3.5.3
          Java version: 1.8.0_161, vendor: Oracle Corporation
          Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre
          Default locale: en_US, platform encoding: UTF-8
          OS name: "linux", version: "3.10.0-693.17.1.el7.x86_64", arch: "amd64", family: "unix"
          1.5.0"

          Analysis:

          withMaven wrapper adds stdout info, that cannot be removed, disabled, according to source:

          https://github.com/jenkinsci/pipeline-maven-plugin/blob/b150161c91769de782af6c5b2ebe7907a4bd17b0/jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/WithMavenStepExecution2.java

          However, that breaks the way we gets output with mvn command.

          Workaround: specifically to maven-help-plugin, I can redirect output to a file, and readFile that.

          Long-term solution (exclusive choice):

          1/ add a silent field to withMaven, to disable any output?

          2/ add a showDebug field to show debug info

          3/ do not show debug info, except when mvn command fails

          Thank you.
          Expected behavior:

          In pipeline:

           
          {code:java}
          withMaven(
           maven: mvnId, // Maven installation declared in the Jenkins "Global Tool Configuration"
           mavenSettingsConfig: mvnSettingsId, // Maven settings.xml file defined with the Jenkins Config File Provider Plugin
           mavenLocalRepo: mavenLocalRepo
           )
          { result = sh( returnStdout: true, script: 'mvn org.apache.maven.plugins:maven-help-plugin::evaluate -Dexpression=project.version -q -DforceStdout -B" ) }
          {code}
           

          result variable value is "
          {noformat}
          1.5.0{noformat}
          "

          Actual behavior:

          result variable is:

          "
          {noformat}
          ----- withMaven Wrapper script -----
           Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T19:49:05Z)
           Maven home: /var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/mvn-3.5.3
           Java version: 1.8.0_161, vendor: Oracle Corporation
           Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre
           Default locale: en_US, platform encoding: UTF-8
           OS name: "linux", version: "3.10.0-693.17.1.el7.x86_64", arch: "amd64", family: "unix"
           1.5.0{noformat}
          "

          Analysis:

          withMaven wrapper adds stdout info, that cannot be removed, disabled, according to source:

          [https://github.com/jenkinsci/pipeline-maven-plugin/blob/b150161c91769de782af6c5b2ebe7907a4bd17b0/jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/WithMavenStepExecution2.java]

          However, that breaks the way we gets output with mvn command.

          Workaround: specifically to maven-help-plugin, I can redirect output to a file, and readFile that.

          Long-term solution (exclusive choice):
           # add a silent field to withMaven, to disable any output?
           # add a showDebug field to show debug info
           # do not show debug info, except when mvn command fails

          Thank you.
          Hide
          famod Falko Modler added a comment - - edited

          Same here. I had to add " | tail -1" to my mvn help:evaluate execution.

          Show
          famod Falko Modler added a comment - - edited Same here. I had to add " | tail -1" to my mvn help:evaluate execution.
          cleclerc Cyrille Le Clerc made changes -
          Description Expected behavior:

          In pipeline:

           
          {code:java}
          withMaven(
           maven: mvnId, // Maven installation declared in the Jenkins "Global Tool Configuration"
           mavenSettingsConfig: mvnSettingsId, // Maven settings.xml file defined with the Jenkins Config File Provider Plugin
           mavenLocalRepo: mavenLocalRepo
           )
          { result = sh( returnStdout: true, script: 'mvn org.apache.maven.plugins:maven-help-plugin::evaluate -Dexpression=project.version -q -DforceStdout -B" ) }
          {code}
           

          result variable value is "
          {noformat}
          1.5.0{noformat}
          "

          Actual behavior:

          result variable is:

          "
          {noformat}
          ----- withMaven Wrapper script -----
           Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T19:49:05Z)
           Maven home: /var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/mvn-3.5.3
           Java version: 1.8.0_161, vendor: Oracle Corporation
           Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre
           Default locale: en_US, platform encoding: UTF-8
           OS name: "linux", version: "3.10.0-693.17.1.el7.x86_64", arch: "amd64", family: "unix"
           1.5.0{noformat}
          "

          Analysis:

          withMaven wrapper adds stdout info, that cannot be removed, disabled, according to source:

          [https://github.com/jenkinsci/pipeline-maven-plugin/blob/b150161c91769de782af6c5b2ebe7907a4bd17b0/jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/WithMavenStepExecution2.java]

          However, that breaks the way we gets output with mvn command.

          Workaround: specifically to maven-help-plugin, I can redirect output to a file, and readFile that.

          Long-term solution (exclusive choice):
           # add a silent field to withMaven, to disable any output?
           # add a showDebug field to show debug info
           # do not show debug info, except when mvn command fails

          Thank you.
          Expected behavior:

          In pipeline:

           
          {code:java}
          withMaven(
           maven: mvnId, // Maven installation declared in the Jenkins "Global Tool Configuration"
           mavenSettingsConfig: mvnSettingsId, // Maven settings.xml file defined with the Jenkins Config File Provider Plugin
           mavenLocalRepo: mavenLocalRepo
           )
          {
             result = sh(
                returnStdout: true,
                script: 'mvn org.apache.maven.plugins:maven-help-plugin::evaluate -Dexpression=project.version -q -DforceStdout -B" )
          }
          {code}
           

          Desired result variable value:
          {noformat}
          1.5.0{noformat}
           

          Actual result variable:
          {noformat}
          ----- withMaven Wrapper script -----
           Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T19:49:05Z)
           Maven home: /var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/mvn-3.5.3
           Java version: 1.8.0_161, vendor: Oracle Corporation
           Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/jre
           Default locale: en_US, platform encoding: UTF-8
           OS name: "linux", version: "3.10.0-693.17.1.el7.x86_64", arch: "amd64", family: "unix"
           1.5.0{noformat}
          Analysis:

          withMaven wrapper adds stdout info, that cannot be removed, disabled, according to source:

          [https://github.com/jenkinsci/pipeline-maven-plugin/blob/b150161c91769de782af6c5b2ebe7907a4bd17b0/jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/WithMavenStepExecution2.java]

          However, that breaks the way we gets output with mvn command.

          Workaround: specifically to maven-help-plugin, I can redirect output to a file, and readFile that.

          Long-term solution (exclusive choice):
           # add a silent field to withMaven, to disable any output?
           # add a showDebug field to show debug info
           # do not show debug info, except when mvn command fails

          Thank you.
          Hide
          cleclerc Cyrille Le Clerc added a comment -

          Very valid point. We initially focused on traceability & troubleshootability and we missed this very relevant use case.

          We are doing 2 things that cause problems for your use case:

          • Troubleshootability: we make visible that the `mvn` call goes through the "wrapper script" that we create to inject Maven parameters (settings files...) outputting the message "withMaven Wrapper script" (here)
          • Traceability: we always add the `mvn` CLI argument `--show-version` (here)

          Both should become 'optional', maybe we can even remove the troubleshootability message as the feature is mature and we have not heard of problems caused by this wrapper script.

          Show
          cleclerc Cyrille Le Clerc added a comment - Very valid point. We initially focused on traceability & troubleshootability and we missed this very relevant use case. We are doing 2 things that cause problems for your use case: Troubleshootability: we make visible that the `mvn` call goes through the "wrapper script" that we create to inject Maven parameters (settings files...) outputting the message "withMaven Wrapper script" ( here ) Traceability: we always add the `mvn` CLI argument `--show-version` ( here ) Both should become 'optional', maybe we can even remove the troubleshootability message as the feature is mature and we have not heard of problems caused by this wrapper script.
          Hide
          delitescere Josh Graham added a comment -

          A solution more keeping with *ix command line tooling is that this sort of additional log / debug information go to stderr, not stdout.

          Show
          delitescere Josh Graham added a comment - A solution more keeping with *ix command line tooling is that this sort of additional log / debug information go to stderr, not stdout.
          Hide
          belpk K P added a comment -

          This indeed breaks the possibility to make easy use of the maven-help-plugin to get e.g. a pom version, pom artifact, etc. when used inside a withMaven() block.
          ... which is actually the method suggested here https://jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#readmavenpom-read-a-maven-project-file , instead of readMavenPom. (except they don't explicitly suggest to put it inside a withMaven())

          In my case, I got around this by further manipulating the variable with some Groovy code to extract the relevant part of the output. ( result.substring(result.lastIndexOf("\n") – after verifying it actually contains a newline "\n", to avoid this breaking if ever the behaviour of withMaven and its output would change again). Adding a "| tail -1" was not an option in my case, as it was running on Windows.

          Note: even if this behaviour of withMaven() wouldn't be changed, it may be a good idea to inform the maintainers of the Pipeline Utility Steps so this could be indicated in their doc, as I suppose more users may struggle with this when merely following that doc?

          Show
          belpk K P added a comment - This indeed breaks the possibility to make easy use of the maven-help-plugin to get e.g. a pom version, pom artifact, etc. when used inside a withMaven() block. ... which is actually the method suggested here https://jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#readmavenpom-read-a-maven-project-file , instead of readMavenPom. (except they don't explicitly suggest to put it inside a withMaven()) In my case, I got around this by further manipulating the variable with some Groovy code to extract the relevant part of the output. ( result.substring(result.lastIndexOf("\n") – after verifying it actually contains a newline "\n", to avoid this breaking if ever the behaviour of withMaven and its output would change again). Adding a "| tail -1" was not an option in my case, as it was running on Windows. Note: even if this behaviour of withMaven() wouldn't be changed, it may be a good idea to inform the maintainers of the Pipeline Utility Steps so this could be indicated in their doc, as I suppose more users may struggle with this when merely following that doc?
          abcd1234 Garr made changes -
          Comment [ Is there a way around this? I'm even trying to log to a temporary file and I'm still seeing the stdout info. ]
          Hide
          abcd1234 Garr added a comment -

          +1 for adding " | tail -1" to mvn help:evaluate.

          Show
          abcd1234 Garr added a comment - +1 for adding " | tail -1" to mvn help:evaluate.
          aheritier Arnaud Héritier made changes -
          Assignee Alvaro Lobato [ alobato ]
          aheritier Arnaud Héritier made changes -
          Assignee Arnaud Héritier [ aheritier ]
          aheritier Arnaud Héritier made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          Hide
          aheritier Arnaud Héritier added a comment -

          there is a PR : https://github.com/jenkinsci/pipeline-maven-plugin/pull/315

          I assign the case to me because I don't find an account here for tkalmar

          Show
          aheritier Arnaud Héritier added a comment - there is a PR : https://github.com/jenkinsci/pipeline-maven-plugin/pull/315 I assign the case to me because I don't find an account here for tkalmar
          aheritier Arnaud Héritier made changes -
          Released As pipeline-maven 3.10.0
          Resolution Fixed [ 1 ]
          Status In Progress [ 3 ] Fixed but Unreleased [ 10203 ]
          Hide
          vovtz Vincent van ’t Zand added a comment -

          When will this be released? I want to do exactly the same thing.

          Show
          vovtz Vincent van ’t Zand added a comment - When will this be released? I want to do exactly the same thing.
          Hide
          vovtz Vincent van ’t Zand added a comment -

          When will this be released?

          Show
          vovtz Vincent van ’t Zand added a comment - When will this be released?
          Hide
          aheritier Arnaud Héritier added a comment -

          it was released in version 3.10 https://github.com/jenkinsci/pipeline-maven-plugin/releases/tag/pipeline-maven-3.10.0

           

          I forgot to update the task here

          Show
          aheritier Arnaud Héritier added a comment - it was released in version 3.10 https://github.com/jenkinsci/pipeline-maven-plugin/releases/tag/pipeline-maven-3.10.0   I forgot to update the task here
          aheritier Arnaud Héritier made changes -
          Status Fixed but Unreleased [ 10203 ] Closed [ 6 ]

            People

            Assignee:
            aheritier Arnaud Héritier
            Reporter:
            antoinetran Antoine Tran
            Votes:
            5 Vote for this issue
            Watchers:
            12 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: