user9836191
user9836191

Reputation: 53

Creating custom steps in groovy

I'm working with jenkins pipeline and have a shared global library. I created several functions that users can use, however the main problem I'm facing is having better output in the Console Output and Blue Ocean: Is there a way to create in groovy a named block (such as when calling the sh function all the output is contained inside)? I tried playing around with stages like so:

stage('Checkout') {
    checkout scm
    stage('Some Custom Step') {
        // Some custom step logic
    }
}

However this approach didn't work. I know you can create custom steps by writing plugins for Jenkins and then calling the function in your groovy script, I was just wandering if there is a way to write such a thing directly in groovy, say, in my library.

Also is there a way to silence output?

sh '<some command with meaningful output>'
sh '<some random output not relevant to the user>' // 
Silence somehow
echo 'step finished successfuly!'

Thanks for everyone in advance

Upvotes: 3

Views: 927

Answers (1)

I don't really know if you can write a step inside pipeline and would like to know that too, but as for silencing the output you can do as mentioned on this question: redirect output to '/dev/null'.

It should be something like

sh '<some command with meaningful output>'
sh '<some random output not relevant to the user> > dev/null'

Upvotes: 1

Related Questions