4

I've trying to find some simple examples of how to use Jenkins git client plugin without much luck. I am not importing the git-client-plugin properly when I run execute a groovy script (using the groovy plugin).

import org.jenkinsci.plugins.gitclient; import hudson.EnvVars; import hudson.util.StreamTaskListener; StreamTaskListener stl = new StreamTaskListener(); EnvVars env = new EnvVars(); GitClient git = Git.with(stl, env) .in('tbd') .getClient(); 

This is the error I am getting when I run the groovy script. The classes in hudson are being imported fine.

startup failed: Script1.groovy: 1: unable to resolve class org.jenkinsci.plugins.gitclient @ line 1, column 1. import org.jenkinsci.plugins.gitclient; ^ 

What changes would I need to make to import git client?

6
  • Try using a system Groovy script instead of a regular Groovy script - it's a different build step option. Also, make sure the plugn is installed and enabled on the Jenkins master that you're trying to run the script against. Commented Sep 8, 2014 at 22:26
  • I'm not sure what exactly You try to import. This org.jenkinsci.plugins.gitclient is only the beginning of some package. Commented Sep 9, 2014 at 9:05
  • @gareth_bowles I tried using system Groovy script which also gives the same error. The git client is installed but I'm not sure how to check if it is enabled on the Jenkins master. Commented Sep 9, 2014 at 14:58
  • @Opal I am using this as an example but I get the error 'unable to resolve class GitClient' so that's why I tried to include that package. Commented Sep 9, 2014 at 15:00
  • You've to import it properly: import org.jenkinsci.plugins.gitclient.GitClient. Commented Sep 9, 2014 at 15:09

1 Answer 1

3

As mentioned in the comments, you need a more general import.

Gitclient is the package, if you want to import all the classes in that package you must add:

import org.jenkinsci.plugins.gitclient.*; 

Or just the two classes you're using:

import org.jenkinsci.plugins.gitclient.Git; import org.jenkinsci.plugins.gitclient.GitClient; 

hth

Sign up to request clarification or add additional context in comments.

1 Comment

Is the above mentioned "system Groovy script" neccessary or did it work with the normal pipeline step?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.