Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write log from Jenkinsfile

When creating Jenkins pipelines or libraries which should be used in a pipeline it's often hard to debug code with the logging options provided. At the moment I'm logging with this:

node {
  ...
  sh "echo ${thingtoshow}"
}

The downside is that this it's not very powerful when it comes to Groovy/Java specific details - e.g. it wouldn't allow me to dump the contents of objects right away

It creates a mess in the actual logs:

[Pipeline] sh
[workspace] Running shell script
+ echo 'things'
things

So how could I write logs to just get a single line of log output within the Jenkins console?


Edit: Even though the code example doesn't show it, but this is particularly useful when developing shared Groovy libraries for Jenkins pipelines

like image 982
pagid Avatar asked Feb 09 '17 20:02

pagid


People also ask

How do you write Jenkinsfile?

To get started quickly with Pipeline: Copy one of the examples below into your repository and name it Jenkinsfile. Click the New Item menu within Jenkins. Provide a name for your new item (e.g. My-Pipeline) and select Multibranch Pipeline.

How do you write a Jenkinsfile pipeline?

To create a simple pipeline from the Jenkins interface, perform the following steps: Click New Item on your Jenkins home page, enter a name for your (pipeline) job, select Pipeline, and click OK. In the Script text area of the configuration screen, enter your pipeline syntax.


1 Answers

You could use the echo stage:

node {
  echo "qwerty"
}

It results in two lines:

[Pipeline] echo
qwerty

Unfortunately it generates two lines, but as far as i know that is the shortest form.

like image 174
Jon S Avatar answered Sep 23 '22 10:09

Jon S