Set environment variable via groovy

1,655 views
Skip to first unread message

wildejenkins

unread,
Jun 27, 2012, 12:44:30 PM6/27/12
to jenkins...@googlegroups.com
Hi,

I’ve been attempting to set an environment variable using groovy. So far the code I have is:

import hudson.model.*
import hudson.maven.*
import hudson.tasks.*

for(item in Hudson.instance.items) {
    item.buildWrappers.each{
      if (it instanceof hudson.plugins.setenv.SetEnvBuildWrapper){        
         println("Instance of hudson.plugins.setenv.SetEnvBuildWrapper ")   
        // do something
      }            
    }
}
But the buildwrapper is never recognised as an instance of SetEnvBuildWrapper. Does anyone know the correct syntax to getting this working?

Thanks,

Andy.

Grégory Boissinot

unread,
Jun 27, 2012, 4:27:45 PM6/27/12
to jenkins...@googlegroups.com
I suggest using EnvInject Jenkins plugin which provide some simple Groovy capabilities to set environment variables.

Sami Tikka

unread,
Jun 27, 2012, 6:51:47 PM6/27/12
to jenkins...@googlegroups.com
Maybe you need to create a new SetEnvBuildWrapper and add it to buildwrappers?

-- Sami
Reply all
Reply to author
Forward
0 new messages