Generate stage from script stdout

18 views
Skip to first unread message

Yeikel Santana

unread,
Aug 18, 2019, 3:31:17 PM8/18/19
to Jenkins Users
Dear Jenkins Community,

I am aware that we can generate dynamic stages using groovy scripts. Question is, can we also do this from the standard output of a script?

For example, I have a script written in Nodejs that I execute with "sh node script.js" and that It can produce standard output to the console.I would like to use its outputs to generate new stages . Is this possible? Do I need to parse the output from groovy in order to do something like this?

I would like to avoid rewriting this script to groovy as much as possible.

Thank you!

jeremy mordkoff

unread,
Aug 19, 2019, 1:02:04 PM8/19/19
to Jenkins Users
yes. You can generate groovy code using any tool you want and then use load to import it, e.g. 

node('docker') {
    checkout scm
    // this step generates Jenkinsfile.do_merge
    sh script: './bin/git/needs_merging -j'
    pipeline = load 'Jenkinsfile.do_merge'
    pipeline.execute()
}


and the generated code looks like 

$ cat Jenkinsfile.do_merge 
// Jenkins job definition for the daily-merge job.
// 
// GENERATED by needs_merging 
//
// DO NOT EDIT
//


def execute() {
/// your code goes here
}

return this
Reply all
Reply to author
Forward
0 new messages