Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support coloring of labels of pipeline's "parallel" command #82

Closed
DenizThatMenace opened this issue Oct 31, 2016 · 9 comments
Closed
Labels
feature request ✨ New feature to be added wontfix

Comments

@DenizThatMenace
Copy link

I tried to colorize the label-output of Pipeline's parallel command.

def taskName = "\u001B[31mLabel in red\u001B[0m";
def task = { echo "\u001B[34mBody in blue\u001B[0m"; }
parallel( "${taskName}", task );

However, it seems the label is just printed verbatim. Only the body is printed in color.
The output looks like this (with Body in blue in blue color).

[[31mLabel in red[0m] Body in blue

Please forgive me, if this issue should be raised against Pipeline and its parallel command. However, maybe it is enough to adjust your plugin so that it supports that feature.

@dblock dblock added the feature request ✨ New feature to be added label Oct 31, 2016
@dblock
Copy link
Member

dblock commented Oct 31, 2016

Seems like a legit feature request.

@dblock
Copy link
Member

dblock commented Nov 7, 2016

Does #83 help with this?

@cpoenisch
Copy link
Contributor

Sorry, #83 will not solve this request, because label output of parallel is interpreted as plain text here.

@DenizThatMenace
Copy link
Author

Sadly, I can confirm that even with #83 the label output of parallel is interpreted as plain text.
I guess, the internals of parallel must be changed to support coloring?

@JoeMerten
Copy link
Collaborator

Tried out the above mentioned example on Jenkins 2.32.3:

def taskName = "\u001B[31mLabel in red\u001B[0m";
def task = { echo "\u001B[34mBody in blue\u001B[0m"; }
parallel( "${taskName}", task );

but got an exception:

java.lang.IllegalArgumentException: Expected named arguments but got [�[31mLabel in red�[0m, org.jenkinsci.plugins.workflow.cps.CpsClosure2@efe9b4e]

@Bagira80, could you please make your example complete and running?
I also miss something like a ansiColor('xterm') { … }.

@JoeMerten
Copy link
Collaborator

JoeMerten commented Mar 23, 2017

I'd never worked with parallel until now, but tried to create an example based on https://github.com/jenkinsci/pipeline-examples/blob/master/pipeline-examples/parallel-from-list/parallelFromList.groovy.
Unfortunetely, my example is definitively not minimal and I'm not sure if I'd applied the ansiColor('xterm') { … } in a right way:

ansiColor('xterm') {
    // Our initial list of strings we want to echo in parallel
    def stringsToEcho = ["a", "b", "c", "d"]
    // The map we'll store the parallel steps in before executing them.
    def stepsForParallel = [:]
    for (int i = 0; i < stringsToEcho.size(); i++) {
        // Get the actual string here.
        def s = stringsToEcho.get(i)
        def color = "${i+31}"
        // Transform that into a step and add the step to the map as the value, with a name for the parallel step as the key. Here, we'll just use something like "echoing (string)"
        def stepName = "echoing \u001B[${color}mCOLOR\u001B[m ${s}"
        stepsForParallel[stepName] = transformIntoStep(s + "\u001B[${color}mCOLOR\u001B[m")
    }
    // Actually run the steps in parallel - parallel takes a map as an argument, hence the above.
    parallel stepsForParallel
} // ansiColor

// Take the string and echo it.
def transformIntoStep(inputString) {
    // We need to wrap what we return in a Groovy closure, or else it's invoked when this method is called, not when we pass it to parallel.
    // To do this, you need to wrap the code below in { }, and either return that explicitly, or use { -> } syntax.
    return {
        node {
            echo inputString
        }
    }
}

And the result is:
ansicolor-parallel

Finally the same conclusion as found out by Bygira80: "… the label is just printed verbatim. Only the body is printed in color."

It might be related to #104.

@stale
Copy link

stale bot commented May 28, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label May 28, 2021
@herter4171
Copy link

Hello, I would like this feature. Color renders properly during the initial run, but color often doesn't persist when the page is reopened. In my pipeline, I have ansiColor set to xterm in the options block and around steps that will print in color, but color is still dropped in parallel stages after a reload.

Original page showing colors like it should:
image

Portion of the exact same log after loading in a new tab:
image

@stale stale bot removed the wontfix label Jun 15, 2021
@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Apr 16, 2022
@stale stale bot closed this as completed Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request ✨ New feature to be added wontfix
Projects
None yet
Development

No branches or pull requests

5 participants