jenkinsci / ansicolor-plugin

Jenkins ANSI Color Plugin
https://plugins.jenkins.io/ansicolor/
MIT License
252 stars 83 forks source link

Allow global setting #2

Closed ctrabold closed 5 years ago

ctrabold commented 12 years ago

The plugin is very useful. The only thing that's nagging me is, that I have to enable it in every job. Given I have > 100 Jobs, this gets quite cumbersome ;)

What do you think about a global switch for enabling it per default?

dblock commented 12 years ago

It's a good idea. When I was coding this I couldn't find how to do it. Pull requests welcome!

ctrabold commented 12 years ago

I would like to help but don't know either. Sorry.

tpot commented 8 years ago

I use a wrapper in Jenkins Job builder to ensure that the plugin is enabled for all my jobs:

http://docs.openstack.org/infra/jenkins-job-builder/wrappers.html

dblock commented 8 years ago

@tpot It would be great to document this in README somehow, please contribute!

dsaita commented 8 years ago

On jenkins 1.609 and plugin version 0.4.1 run this script on YOUR_JENKINS_URL/script :

def jobs = hudson.model.Hudson.instance.items
jobs.each { job ->
    def has_color_wrapper = false
    job.buildWrappersList.each { wrapper ->
      if (wrapper instanceof hudson.plugins.ansicolor.AnsiColorBuildWrapper) {
        has_color_wrapper = true
        println("$job.name is already configured.")
      }
    }
    if (!has_color_wrapper) {
        println("Adding AnsiColor to $job.name")
        job.buildWrappersList.add(new hudson.plugins.ansicolor.AnsiColorBuildWrapper("xterm"));
        job.save()
    }
}

On jenkins 2.3 and plugin version 0.4.2 run this script on YOUR_JENKINS_URL/script :

def jobs = hudson.model.Hudson.instance.items
jobs.each { job ->
    def has_color_wrapper = false
    job.buildWrappersList.each { wrapper ->
      if (wrapper instanceof hudson.plugins.ansicolor.AnsiColorBuildWrapper) {
        has_color_wrapper = true
        println("$job.name is already configured.")
      }
    }
    if (!has_color_wrapper) {
        println("Adding AnsiColor to $job.name")
        job.buildWrappersList.add(new hudson.plugins.ansicolor.AnsiColorBuildWrapper("xterm", 1, 2));
        job.save()
    }
}
tknerr commented 7 years ago

+1, especially in the context of Jenkins 2.x Pipeline builds a global setting would be super useful. Enabling colored output is a cross-cutting concern that you may not want to repeat in each and every Jenkinsfile.

Will give @dsaita 's workaround a try...

UPDATE: no luck on first attempt, got:

groovy.lang.MissingPropertyException: No such property: buildWrappersList for class: org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
    at org.codehaus.groovy.runtime.callsite.GetEffectivePojoPropertySite.getProperty(GetEffectivePojoPropertySite.java:66)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:296)
    at Script1$_run_closure1.doCall(Script1.groovy:6)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024)
    at groovy.lang.Closure.call(Closure.java:414)
    at groovy.lang.Closure.call(Closure.java:430)
...
tknerr commented 7 years ago

Another approach I was thinking about was redefining the sh step from within a global library, but

  1. my groovy foo is a bit outdated and first experiments not successful
  2. I don't know if redefining pipeline DSL steps would work at all or is guarded against somewhere
subos2008 commented 7 years ago

If we can't have a truly global setting - can we have a one liner for pipeline jobs that doesn't use a block? I'm new to pipeline but having all these wrapper blocks seems a bit ridiculous.

ericfrancis commented 7 years ago

@subos2008 were you able to find a solution?

subos2008 commented 7 years ago

@ericfrancis not yet. Perhaps the declarative style makes it easier, but our pipelines aren't simple enough to use declarative style at the moment.

ericfrancis commented 7 years ago

@subos2008 I was able to wrap all with:

#!groovy

pipeline {
  agent any

  options {
    buildDiscarder logRotator(daysToKeepStr: '5')
    timeout(time: 10, unit: 'MINUTES')
    ansiColor('xterm')
  }
subos2008 commented 7 years ago

@ericfrancis Yep, that's the new declarative style for pipelines. Vastly improves this kind of thing. However, the declarative style is (currently) much more limited. A solution for the traditional groovy script would be much appreciated - which is what this thread is about. (aiui)

shiranhonigFiverr commented 6 years ago

Any progress on this issue?

nickbroon commented 5 years ago

An equivalent global config was added to the timestamper plugin here: https://github.com/jenkinsci/timestamper-plugin/commit/1afb7d4b4077c7aa7660794d75e018def8ba08c0

It would be great to see a global config option for ansicolor

dblock commented 5 years ago

Please contribute!

hashar commented 5 years ago

Thank you @kcboschert :+1:

zxti commented 4 years ago

Hi, would you consider cutting a new release so we can use this great feature? Thanks!

dblock commented 4 years ago

Hi, would you consider cutting a new release so we can use this great feature? Thanks!

https://github.com/jenkinsci/ansicolor-plugin/issues/166