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