Unfortunately that does not seem to work because the build.getEnvironment(listener) parts raises the exception.