How to import the jenkins-api in Groovy?
Asked Answered
J

1

3

I have a small groovy script that I want to edit and I have issues with the dependency management in Groovy. I am new to groovy and sorry in advance if this question is kinda studip / easy to answer. I use IntelliJ as IDEA.

@Grab(group='org.jenkins-ci.main', module='jenkins-core', version='2.167', scope='provided')
//import jenkins...

def call()
{
    Jenkins.instance.getItemByFullName(currentBuild.fullProjectName).getBuilds().each{ build ->

        if (currentBuild.number > build.number && exec != null)
        {
           build.rawBuild.doKill()
        }
    }
}

I try to use the jenkins-core dependency to get the autocomple of the code, documentation etc. etc. for the code but it simply does not work. I also tried the maven dependency in the pom it does work neither.

So now to my question: How do I import the dependency of Jenkins correctly in Groovy?

Jamajamaal answered 6/3, 2019 at 6:18 Comment(0)
P
2

You can get this dependency from jenkins-ci maven repo:

@GrabResolver(name='jenkins', root='http://repo.jenkins-ci.org/public/')
@Grab(group='org.jenkins-ci.main', module='jenkins-core', version='2.167')
Professionalism answered 6/3, 2019 at 8:43 Comment(6)
I get the following error. Findbugs in the release maybe? @Grab(group='org.jenkins-ci.main', module='jenkins-core', version='2.9'): 0 jars Error grabbing Grapes -- [download failed: com.google.code.findbugs#jsr305;2.0.1!jsr305.jar] WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1Jamajamaal
I am using Java 11 and Groovy 3.0.0-alpha4Jamajamaal
Findbugs hasn't been updated in a few years. Looks like it doesn't work on JDK 11Professionalism
Unfortunately I am still not able to get a working setup. Do you know which Java JDK works with the jenkins-ci maven repo?Jamajamaal
JDK 8. Here you can find more detailed info: jenkins.io/doc/administration/requirements/javaProfessionalism
It finally worked, thanks god! I had to delete the .groovy and .m2 folder and do the Grab again. Thanks for your help!Jamajamaal

© 2022 - 2024 — McMap. All rights reserved.