Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

Import groovy script from file #3736

SameOldSong ·

In our project, we often write Groovy scripts either in Pre-/Post-Execute Action or in separate step Execute script.
Something like this script - https://support.pmease.com/PMEase/QuickBuild-Scripts-Plugins/topics/3328/groovy-script-to-get-names-of-all-steps-in-a-configuration?5

The scripts can be quite long. Is there a possibility to store such a script in a .groovy file and then refer to this file in the script field?
Something like:
evaluate(new File("../scripts/script.groovy"))

Thanks in advance for any suggestions/ideas

  • replies 4
  • views 3821
  • stars 0
robinshen ADMIN ·

You may read the file to a string with groovy, and call groovy's eval to evaluate the string. You may pass in some QB objects as eval context (such as system, build, etc) if necessary

SameOldSong ·

Thanks a lot. This worked. In case someone is interested, here is a simple example:

groovy:

def sharedData = new Binding()                          
def shell = new GroovyShell(sharedData)                 
sharedData.setProperty('configuration', configuration)     
 
logger.info(shell.evaluate(new File('J:\\temp\\simpleScript.groovy')));

And here is the content of simpleScript.groovy

return configuration.getPathName();
robinshen ADMIN ·

Thanks for sharing. In QB9 we will be adding a separate step to execute script in a file.

BUROTTO ·

Decent need to accomplish something like this with mine