Closed ctrabold closed 5 years ago
It's a good idea. When I was coding this I couldn't find how to do it. Pull requests welcome!
I would like to help but don't know either. Sorry.
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
@tpot It would be great to document this in README somehow, please contribute!
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()
}
}
+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)
...
Another approach I was thinking about was redefining the sh
step from within a global library, but
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.
@subos2008 were you able to find a solution?
@ericfrancis not yet. Perhaps the declarative style makes it easier, but our pipelines aren't simple enough to use declarative style at the moment.
@subos2008 I was able to wrap all with:
#!groovy
pipeline {
agent any
options {
buildDiscarder logRotator(daysToKeepStr: '5')
timeout(time: 10, unit: 'MINUTES')
ansiColor('xterm')
}
@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)
Any progress on this issue?
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
Please contribute!
Thank you @kcboschert :+1:
Hi, would you consider cutting a new release so we can use this great feature? Thanks!
Hi, would you consider cutting a new release so we can use this great feature? Thanks!
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?