Transform standard output from Gradle's Exec task on the fly? - gradle

Is it possible to transform the standard output logs that a Gradle Exec task produces, on the fly?
We have a task executing a command line tool that takes about a minute to run which logs a lot. I would like to filter out just a few of those lines and log them to show progress without cluttering the build log.

You could set your own OutputStream implementation with Exec.setStandardOutput. Or you could execute a shell command that runs the tool and filters its output.

Related

How to determine what gradle command was running

I want to measure time of execution for different gradle command so I have to know what exactly command was run.
For example when I execute from terminal
./gradlew clean
If I execute
./gradlew assembleDebug
desired result is "assembleDebug"
I know I can get list of tasks with project.tasks, but it will give me only list of tasks which my command will execute, without command that started them all.
Is there any option to determine that "first" command?
I figured out how that should work
project.gradle.startParameter.taskNames
gives list of task names. For example if I run multiple commands like
./gradlew app:clean app:cleanBuildCache
it will contain both commands.
Is is possible to cast it for string directly
project.gradle.startParameter.taskNames.toString()
So I will have
[app:clean, app:cleanBuildCache]
With single command like
./gradlew app:clean
I receive
[app:clean]
and that was what I searched for

Choice paramter in jenkins as an output from shell script (pipeline)

I'm looking for a way to use an output from shell as a jenkins parameter but in pipeline, don't want to use any of UI plugins.
For example I want to use output from command
ls /home
as a choice parameter (so I would be able to choose users from the list), is it possible to do something like that?
It must be done in pipeline, I'm not looking for some plugins which allow you to do something like that, but you need to do all in UI, if plugin support pipelines then it's also ok.
For a pipeline to run, its parameters need to be completely defined before the pipeline is started.
For the pipeline to parse the output of ls /home, it needs to run and allocate a node and a workspace, which can only happen after the pipeline is started.
So you are in a kind of a chicken-and-egg problem, where you need to run some code before you start a pipeline, but you can't run pipeline before you run that code.
So your issue boils down to "How can I run some arbitrary Groovy script before I start my pipeline?"
There are two options for this:
ActiveChoice plugin allows you to define a parameter that returns a script. Jenkins will then run the script (don't forget to approve it) in order to show you your "Build with parameters" page. Debugging this is notoriously hard, but this can go to great lengths.
Alternatively, you may want to run a scripted pipeline before you run the Declarative (main) one, as outlined e.g. in this answer. This may look a bit like this:
def my_choices_list = []
node('master') {
stage('prepare choices') {
// read the folder contents
def my_choices = sh script: "ls -l /home", returnStdout:true
// make a list out of it - I haven't tested this!
my_choices_list = my_choices.trim().split("\n")
}
}
pipeline {
parameters {
choiceParam('OPTION', my_choices_list)

How to a execute list of commands in parallel in snakemake

I have a snakemake rule that creates a text file will many shell commands as its output. I would like to design a second rule that would take the file as an input and run all the commands specified in the file in parallel - taking advantage of multiple threads/cores or submitting the commands to a cluster if --cluster is specified. Is that possible?
You could write python code, either using the "run:" block in snakemake or "script:" with an external python script, which uses the subprocess module to run each command in the file in a separate process. I don't think there's a way to do it more directly in Snakemake.

How can a CSharpScript process to capture the output generated by a vbscript or cs-script?

Is there a way for the hosting process to capture the output generated by a vbScript or cs-script when that script is run by CSharpScript(Rosslyn) ?
I am running a Rosslyn script in C#. I would like to log the Console or Trace output generated by the script. I expected something similar to OpenStandardOutput in System.Console, but am not finding it.
When your CSharpScript is executed it is simply running as code within your calling process. If you want to capture its output you can use the technique of starting a new process to run the script and redirecting its output.
Try this link.

Capture output of tests in gradle

How do I capture the standard output and standard error from all test tasks in gradle? For exec tasks, I can just say standardOutput = new ByteAr... and it works - but test tasks don't seem to have a standard out.
What I'm looking to achieve is simple. (Actually, I want this for ALL gradle tasks, but test tasks are most important).
If the task succeeds...
I get no output at all
If the task fails
I get the most detailed output possible.
Simple as that. How do I achieve this?

Resources