Jenkins: Changing Console Output - jenkins

I am working in jenkins.
I'd like to put some specified text in the Console Output in a specified colour.
For example:
My output is:
Commit message....
Creating dir: /var/lib/1
Creating dir: /var/lib/2
Job done
Build Successful
I'd like to out "Job Done" in red.
How can I do this?
I've looked at some plugins (The parsed log, AnsiColor Plugin) but I think I cannot do this using it.

The Log Parser plugin will do what you want.
It allows you to specify your own rules with a parsing rules file and regular expression like syntax.

Related

How to eliminate leading [java] label from Ant's <java> task output?

I'm invoking the <java> task using Ant to run a program that prints out some stuff to stdout that ultimately, I'd like the user to be able to copy-paste easily. However, each line of stdout is prefixed with [java], which makes things needlessly challenging for the user.
Is there some way to print just the output of System.out.println(...) without getting prefixed with [java]?
Set ANT_ARGS=-emacs, see ant FAQ:
Ant adds a "banner" with the name of the current task in front of all
logging messages - and there are no built-in regular expressions in
your editor that would account for this.
You can disable this banner by invoking Ant with the -emacs switch.
[...]
Also ant manual Running Apache Ant listing all cli options might be helpful :
-emacs, -e produce logging information without adornments

How to programmatically set the Source Encoding for Jenkins Cobertura plugin

We are using Jenkins 1.642.1 and we generate Cobertura reports for both build/deploy jobs and functional test jobs. (It appears we are using Cobertura plugin version 1.9.6) The generated report includes a link to the js source file which included red/green color coding to indicate line hits. This file includes non-ASCII characters so garbage chars are rendered in the html view of this file.
When I check the configuration of the build job (which is generated by groovy scripts) the Source Encoding setting for the 'Publish Cobertura Coverage Report' indicates "ASCII" as the setting. I need it to be UTF-8. I can choose this manually, but we don't mess with our builds manually. Everything is generated in CI style - using programming.
In this case, I see the line in the groovy script and it calls 'cobertura [path to file]'. There doesn't seem to be any room for additional arguments including that for the source encoding. Can someone point me the right direction to set this value programmatically?
Thanks,
Rob
Ah - It appears that you can micro-manage the resulting configuration.xml file via commands in your groovy file like this:
// Configuring Cobertura
project / publishers / "hudson.plugins.cobertura.CoberturaPublisher" {
coberturaReportFile('Directory path')
sourceEncoding(UTF_8)
}

Is there a jenkins plugin to add a why-I-built-this remark, that will appear with 'started by [user]'?

When I run a manual build, I'd often like to mark it with documentation to show why I ran it. Is this feature available with a plugin?
thank you!
I would approach this by adding a build parameter as a string, as above, then use the Description Setter Plugin to set it from that parameter. We use something like this for the regex:
^\++ : BUILD DESCRIPTION : GERRIT_CHANGE_OWNER_EMAIL=([^#\s]*)\S*, BUILD_USER_EMAIL=([^#\s]*)\S*, GERRIT_BRANCH=(\S*), GIT_COMMIT=(\S{8}).*$
and this for the description:
\1\2, \4, \3
As a result we get:
jspain, 0ee3198b, master
or when it fails, we get:
Failed due to timeout.
wayvad, fc7bdf2a, master
this "Failed..." text comes from the Build Timeout Plugin
I am not aware of a plugin that can do this, and after a brief search I could not find one to do what you describe.
You can mimic this behavior by adding a string parameter in the job that takes a default value of automatically started when it's normally run, but that you can change to my reasons for this build when starting it manually.
You could then use a batch (or groovy or ) build step to print the contents of that parameter into the build log. If you do some sort of SCM checkout I'm not sure how close you can get it to print to the line that contains the username that started the job, however you can click on the view parameters button in the job build and see what was in the field quickly without having to parse the logs.
The downside of this is that parameter would have to be added to each job.

Can I stop "Filter says params are" line from being printed to stdout?

A 2.1.1 Grails app has a filter, and in development mode lines like this get printed on every request:
Filter says params are: [controller:book, action:list]
How can I stop this? (I don't think it is anything in my code doing it)
Are you using the functional test plugin? A quick Google search returned the suspect println you're seeing in the functional test plugin's grails-app/conf/TestFilters.groovy filter. If you are using the plugin, it looks like it's been removed/commited in Mar 2012, so you may need an update.
Otherwise if you're not using the functional test plugin, I would inspect your grails-app/conf/ directory for any *Filters.groovy and it's contents.

Fail Jenkins Build based on build output and email failed log sections

I want to make the build fail by analyzing the results of the console log, for a mac project I am building. It builds each module and gives the results like this:
###################################
XX XXX XXX
##########################
It then returns BUILD FAILED
I want to show that the build failed at the end of the console output, and at the same time I want to know which module failed. It should be sent by email since I am already using the email-ext plugin.
I am unsure of what needs to be done; I am aware of text-finder, log parser and setting the run condition - but do not know what steps to follow.
You will need to use the text-finder plugin and the email-ext plugin together in order to accomplish both your objectives.
First set up the text-finder plugin and provide an appropriate regex. Something like: .*(?i)failed.*|.*(?i)error.* would find the words "failed" or "error" in a case insensitive manner. You will need to specify a path to your log files and probably want to check the "Also search console output" check box.
This will cause any build which outputs "failed" or "error" to fail in Jenkins.
Your requirement to email the module which failed is a little more complex, but possible with the email-ext plugin. This plugin allows you to specify a regex which is used to gather email content using a special token which accepts arguments. The full argument list and token name is: ${BUILD_LOG_REGEX, regex, linesBefore, linesAfter, maxMatches, showTruncatedLines, substText, escapeHtml, matchedLineHtmlStyle}
Most of these arguments are optional, something like this should do the trick for you: ${BUILD_LOG_REGEX, regex=".*(?i)failed.*|.*(?i)error.*", linesBefore=10, linesAfter=10}. Put this in the "Default Content" section of the email-ext configuration. You can specify multiple tokens as well, see this answer for instructions to get the full list: Jenkins Email-ext plugin - tokens
You can of course edit the LinesBefore and LinesAfter parameters to suit your needs.

Resources