Over the iterations of grails, the best method to do this has changed. But if you want to execute grails code only within a specific environment in grails 3, you can use the static methods on the
grails.util.Environment class.
Eg:
switch (Environment.getCurrent()) {
case Environment.DEVELOPMENT:
20.times {
//do some thing
}
break;
case Environment.PRODUCTION:
2.times {
//do some other thing
}
break;
}