Calling a maven instance from a plugin

49 views
Skip to first unread message

Dimitri CHARLES

unread,
Nov 14, 2012, 4:11:12 AM11/14/12
to jenkin...@googlegroups.com
Hi, I am actually writing a plugin where I want to pass some customs parameters, goals 

to a maven instance. For instance, some profiles, some properties contained in a POM (-Dproperty=value). 

I tried to look in the jenkins code and I see that the class hudson.tasks.Maven could help me. But I also see there is the

class AbstractMavenBuilder. The idea that I have for the first one is I have a maven property (type of Maven) in my plugin (my plugin is a class that extends Builder),

and I instantiate this property with my custom goals. In my perform method, I call maven.perform(). 

For the  AbstractMavenBuilder,   I discovered it yesterday and I was thinking to extend this class. 

Is this a better way to do that? Can you show an example how to call a maven instance from a plugin?

Thanks for your suggestion

Nord, James

unread,
Nov 14, 2012, 6:28:52 AM11/14/12
to jenkin...@googlegroups.com

Take a look at the m2release plugin – you can dynamically (and optionally) change the default goals that get passed to maven in a plugin.

 

/James





**************************************************************************************
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postm...@nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary.

NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00
**************************************************************************************

Dimitri CHARLES

unread,
Nov 14, 2012, 6:56:48 AM11/14/12
to jenkin...@googlegroups.com
Hi James, 
Thanks for your answer. 

How can I use this plugin. I see that it is used to perform Maven release. Can you give me an example how can I use it?

Thanks

Nord, James

unread,
Nov 14, 2012, 7:04:16 AM11/14/12
to jenkin...@googlegroups.com

Hi Dimitri,

 

Don’t use it – just look at the code which will give you an example of changing the goals.

Dimitri CHARLES

unread,
Nov 14, 2012, 9:37:05 AM11/14/12
to jenkin...@googlegroups.com
Hi James,

Thanks for your answer. 

I watched and it seems that I have to implement MavenArgumentInterceptorAction. 

But in the class M2ReleaseArgumentInterceptorAction, why dont implement the intercept method?

Nord, James

unread,
Nov 14, 2012, 10:03:36 AM11/14/12
to jenkin...@googlegroups.com

It uses the getGoalsAndOptions rather than the intercept.

 

Intercept is more for adding extra options, getGotalsAndOptions is used to change the default goals that run (the ones that are normally entered in the UI).

 

See https://github.com/jenkinsci/jenkins/blob/master/maven-plugin/src/main/java/hudson/maven/MavenArgumentInterceptorAction.java

Dimitri CHARLES

unread,
Nov 14, 2012, 12:03:19 PM11/14/12
to jenkin...@googlegroups.com
Hi James, 

Thanks for your answer. I am able to pass my custom variable to maven but when I am launching a build, I have a strange error : 

saying  : 

Building in workspace D:\workspace2\remote-deployment-new\work\jobs\Maven\workspace
FATAL: The plugin 'com.ebiznext.plugins.RemoteDeploymentWrapper' still uses deprecated setUp(Build,Launcher,BuildListener) method. Update the plugin to use setUp(AbstractBuild, Launcher, BuildListener) instead.
java.lang.AssertionError: The plugin 'com.ebiznext.plugins.RemoteDeploymentWrapper' still uses deprecated setUp(Build,Launcher,BuildListener) method. Update the plugin to use setUp(AbstractBuild, Launcher, BuildListener) instead.
	at hudson.tasks.BuildWrapper.setUp(BuildWrapper.java:144)
	at com.ebiznext.plugins.RemoteDeploymentWrapper.setUp(RemoteDeploymentWrapper.java:100)
	at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.doRun(MavenModuleSetBuild.java:601)
	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:586)


It's strange because I have implemented the correct method, not the deprecated one :

public class RemoteDeploymentWrapper extends BuildWrapper {

  ....

public Environment setUp(@SuppressWarnings("rawtypes") AbstractBuild build, Launcher launcher, final BuildListener listener)
            throws IOException,
            InterruptedException {
         .......
   } 
}

Thanks for your advice !!

Dimitri CHARLES

unread,
Nov 14, 2012, 7:15:48 PM11/14/12
to jenkin...@googlegroups.com
Hi James, I finally corrected my mistakes. 
In fact, in the setUp, instead of returning a new Environment, I just called the super.setUp and that gave the error show above. 

And now, I am returning a new Environment and everything works. Thanks for your help !!
Reply all
Reply to author
Forward
0 new messages