Shared Library - Add dependency to Jenkins

Hi all,

I’m looking for the dependency to add to pom file (maven) in order to use the hudson classes.
for example - to use hudson.model.User.
What is the artifact and group?

Thanks.

Shared libraries don’t need pom, and they get run in the context of jenkins, so shouldn’t need to have any dependencies fetched.

can’t you just import hudson.mode.User in your .groovy file?

I run junit on the shared library project.
And I want them to run locally, before push changes to my SCM.

I recommend GitHub - jenkinsci/JenkinsPipelineUnit: Framework for unit testing Jenkins pipelines then

You can find the artifact and group Id in the pom files in GitHub.com/Jenkinsci/jenkins but I highly recommend the existing testing library

I already use JenkinsPipelineUnit (regards your recommendation :-)).
And still, the import hudson.mode.User is not compile. I guess i have to add dependency to pom. not?

I don’t think you do, but I am not confident.

Its not in https://github.com/jenkins-infra/pipeline-library/blob/f69626d301d174ae0d73593602c52a77eb0aad6c/pom.xml at all

How are you running your tests?

Whats the exact error message? This says hudson.mode not hudson.model

I created project in inteliJ, I add jenkins-pipeline-unit and some more dependencies, like this:

< dependency >
< groupId >com.lesfurets</ groupId >
< artifactId >jenkins-pipeline-unit</ artifactId >
< version >1.1</ version >
< scope >test</ scope >
</ dependency >
< dependency >
< groupId >org.codehaus.groovy</ groupId >
< artifactId >groovy-all</ artifactId >
< version >2.4.11</ version >

</ dependency >
< dependency >
< groupId >org.assertj</ groupId >
< artifactId >assertj-core</ artifactId >
< version >3.7.0</ version >
< scope >test</ scope >
</ dependency >

< dependency >
< groupId >org.junit.jupiter</ groupId >
< artifactId >junit-jupiter-api</ artifactId >
< version >5.8.2</ version >
< scope >test</ scope >
</ dependency >

and some more library I used.

Then, I start write functions to use as shared-liberary in the “var” folder, and junit in the “test” folder.
The mistake hudson.mode is in the topic, not in the code.
When I add the import hudson.model.User and run “mvn compile -DskipTest=true” everything is fine.
When I run “mvn test” I get the following error:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:

file: … Error on loading library my-library@ : startup failed:

… unable to resolve class hudson.model.User