[workflow plugin] Run existing non-CPS and system groovy scripts

135 views
Skip to first unread message

Finn Hughes

unread,
Mar 12, 2015, 4:47:59 PM3/12/15
to jenkins...@googlegroups.com
Hi,

I've had some success with the workflow plugin and each release seems to help significantly :)

I can't see how to call my existing non-CPS groovy scripts, especially the system ones, from my workflow. I can sort of work round the problem by running a job that runs the script but that's very messy.

Anyone know how to do this?

Finn

P.S. thanks to Daniel Beck for pointing out I initially asked this question on the wrong mailing list

Jesse Glick

unread,
Mar 19, 2015, 11:44:49 AM3/19/15
to jenkins...@googlegroups.com
On Thursday, March 12, 2015 at 4:47:59 PM UTC-4, Finn Hughes wrote:
I can't see how to call my existing non-CPS groovy scripts, especially the system ones, from my workflow.

Not quite clear what you are talking about here.

If you mean to run plain old Groovy programs in your workspace, like “Execute Groovy script” in a freestyle project,

node {
  git '…'
  sh 'groovy ./mystuff.groovy'
}

(using the tool step as needed to install Groovy etc.). https://issues.jenkins-ci.org/browse/JENKINS-26635 would make it a little easier.

If you mean to run code inside the Jenkins JVM, you can use `evaluate(String)` (if accessible directly as text) or the `load` step (if a file in a workspace). Both run CPS-transformed.

If you mean to “Execute system Groovy script” like in a freestyle project, then https://github.com/jenkinsci/groovy-plugin/blob/485ba4ace71be1b4c140c20235fdd9c31dd13f72/src/main/java/hudson/plugins/groovy/SystemGroovy.java#L38 would need to implement SimpleBuildStep. Note that this plugin is currently not safe to use in a secured Jenkins installation.

Finn Hughes

unread,
Mar 19, 2015, 11:50:15 AM3/19/15
to jenkins...@googlegroups.com
Thanks for the comprehensive answer to an unclear question. Hopefully I'll be able to try it out soon.

I think you covered each of my use cases. I particularly like that you linked me to the place to look at in SystemGroovy.java :)
Reply all
Reply to author
Forward
0 new messages