Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

How to import the class hudson outside jenkins?

 
Ranch Hand
Posts: 34
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

We are using Jenkins and there is a groovy script created by my colleague but he is on holliday. I have some Java knowledge and I know that I can import a class.

But I will run the groovy script outside Jenkins in the groovy console or eclipse.

It seems to that this must be possible.

But the first line is:


I'm looking in the Jenkins dir to find there the EnvVars class. Till without success.

Maybe I'm searching in the complete wrong direction, but maybe someone can help me out with this or has a suggestion that will put me in the right direction.

Thanks in advance.

BR.

Nico
 
Sheriff
Posts: 22508
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's your reason for trying to access Jenkins internals, like builds, outside of Jenkins? Because I very much doubt you're going to achieve this like this. I'd instead check out the REST API that Jenkins provides.
 
Saloon Keeper
Posts: 24538
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can run Groovy scripts in Jenkins.

https://foxutech.com/how-to-run-groovy-script-in-jenkins/

But, as Rob says, it's very suspicious that the script is tapping to Jenkins/hudson internal resources. Aside form the fragility of such operations, there should be a more direct way of obtaining the environment variables.

After all, when I need environment info in a Java app, I don't yank in a JBoss module to do it, I use the built-in JVM classes.
 
Tim Holloway
Saloon Keeper
Posts: 24538
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul Clapham tells me that his malware detector flagged that page, despite its high Google rankings. It may be infected with malware. Or at least with an obfuscated JavaScript file that contains far too many hexadecimal items for my comfort.

The page itself looked useful, but because of its questionable associations, I'd recommend that you search for an alternate site. Lots of people use Jenkins with Groovy, so there should be some safer ones to get the necessary information from.
 
Rob Spoor
Sheriff
Posts: 22508
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't check that website for obvious reasons, but is it about the same as the Script Console? Or otherwise pipeline jobs? I've worked with both, and you can do a lot with them. Just be careful about leaving the sandbox (which you can only do with inline pipelne jobs).

(I recently even set up a job in Jenkins to reload parts the Jenkins configuration using Jenkins Configuration as Code - push a commit in the config repository and the configuration gets automatically reloaded.)
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic