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

Don't force --batch-mode to benefit of Maven 3.5 colorized output

      I'd like to enable the color console of maven 3.5.0 on Jenkins (using AnsiColorPlugin).

      Currently the pipeline-maven-plugin will force the --batch-mode parameter. As per the documentation: The Maven parameters that are useful on a build server, "--batch-mode" ("-B") and "--show-version" ("-V") are enable by default, no need to add them in your mvn invocations.

      This is what maven says about --batch-mode: Run in non-interactive (batch) mode (disables output color)

      I understand this is a sensible default behavior to set --batch-mode on Jenkins, however I would appreciate it if there was a way I could override these defaults.

      Thanks

       

       

          [JENKINS-44543] Don't force --batch-mode to benefit of Maven 3.5 colorized output

          Daniel Beland added a comment -

          By the way to enable colors through jenkins you also need to specify -Djansi.force=true in mavenOpts

          Daniel Beland added a comment - By the way to enable colors through jenkins you also need to specify -Djansi.force=true in mavenOpts

          Daniel Beland added a comment -

          There seems to be a discussion already to enable colors even in batch mode: https://issues.apache.org/jira/browse/MNG-6220

          I'm ok to wait and see what happens with it before we alter the pipeline-maven-plugin

          Daniel Beland added a comment - There seems to be a discussion already to enable colors even in batch mode: https://issues.apache.org/jira/browse/MNG-6220 I'm ok to wait and see what happens with it before we alter the pipeline-maven-plugin

          Thanks dcendents for your research, I would prefer to get MNG-6220 implemented and keep the batch-mode

          Cyrille Le Clerc added a comment - Thanks dcendents for your research, I would prefer to get MNG-6220 implemented and keep the batch-mode

          Jesse Glick added a comment -

          --batch-mode should stay. The new option is -Dstyle.color=always.

          Jesse Glick added a comment - --batch-mode should stay. The new option is -Dstyle.color=always .

          Daniel Beland added a comment -

          I think we all agreed batch mode should be kept and we can use the new color style property of maven once they add it. So this issue can be closed.

           

          BTW, color style was meant to be in maven 3.5.2 but it is broken: https://issues.apache.org/jira/browse/MNG-6296)

           

          Daniel Beland added a comment - I think we all agreed batch mode should be kept and we can use the new color style property of maven once they add it. So this issue can be closed.   BTW, color style was meant to be in maven 3.5.2 but it is broken: https://issues.apache.org/jira/browse/MNG-6296)  

          Daniel Beland added a comment - - edited

           

          I can confirm it works with maven 3.5.3 but it requires -Dstyle.color=always on the command line and -Djansi.force=true in the mavenOpts.

          e.g. :

          withMaven(mavenOpts: '-Djansi.force=true') {
              sh "mvn clean verify -Dstyle.color=always"
          }

           

          Daniel Beland added a comment - - edited   I can confirm it works with maven 3.5.3 but it requires -Dstyle.color=always on the command line and -Djansi.force=true in the mavenOpts. e.g. : withMaven(mavenOpts: '-Djansi.force= true ' ) { sh "mvn clean verify -Dstyle.color=always" }  

          Thanks dcendents I have few questions please:

          • Do you know why, in your example, `-Djansi.force=true` has to be passed in `mavenOpts` when `-Dstyle.color=true` is passed in in the args of the call?
          • Do you know if passing these args to maven < 3.5.3 could introduce problems?

          Cyrille Le Clerc added a comment - Thanks dcendents I have few questions please: Do you know why, in your example, `-Djansi.force=true` has to be passed in `mavenOpts` when `-Dstyle.color=true` is passed in in the args of the call? Do you know if passing these args to maven < 3.5.3 could introduce problems?

          Daniel Beland added a comment -

           

          I don't know for sure, but assuming maven looks at system properties and not only at the CLI and that all properties passed on the CLI are added to system properties, I would say this is propbably because of the order in which the initialisation is performed.

          MavenCLI -> look for style.color option on CLI only -> Jansi is initialised looks at jansi.force in system properties -> Maven adds -D CLI parameters to system properties.

          As I said this is only a guess.

           

           

          For your second question I'm pretty sure it is safe. I've been running a "hacked" maven 3.5.0 in jenkins (I commented the part where -B would disable colors) and I was passing -Djansi.force=true in maven properties.

           

          As a side note for people reading this post, -Dstyle.color=always|never|auto is used by maven to decide if colors are used and then internally it uses the jansi library to render colors on the console. jansi will try to detect the type of terminal to see if colors are supported and jansi.force=true will override that check (jenkins jobs don't have a terminal that jansi recognizes).

           

          Daniel Beland added a comment -   I don't know for sure, but assuming maven looks at system properties and not only at the CLI and that all properties passed on the CLI are added to system properties, I would say this is propbably because of the order in which the initialisation is performed. MavenCLI -> look for style.color option on CLI only -> Jansi is initialised looks at jansi.force in system properties -> Maven adds -D CLI parameters to system properties. As I said this is only a guess.     For your second question I'm pretty sure it is safe. I've been running a "hacked" maven 3.5.0 in jenkins (I commented the part where -B would disable colors) and I was passing -Djansi.force=true in maven properties.   As a side note for people reading this post, -Dstyle.color=always|never|auto is used by maven to decide if colors are used and then internally it uses the jansi library to render colors on the console. jansi will try to detect the type of terminal to see if colors are supported and jansi.force=true will override that check (jenkins jobs don't have a terminal that jansi recognizes).  

            cleclerc Cyrille Le Clerc
            dcendents Daniel Beland
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: