Extending Maven Runner

Hi

I want to extend the maven runner in the buildAgent to remove some files before every maven project is run. These are not files in the working directory so checking the box to clean everything is not sufficient.

I know this is possible but I was wondering if I could get some direction on how to do this :)

Thanks
Colin

23 comments

Hello Colin,

There is a way of doing this. But it's undocummented and unstable in terms
of API changing.
We're planning to add an ability to extend any build configuration with pre-
and postactions in some future version.

If you need this urgently I can give you a sample code. But no guarantee
this will work in any future update.

Hi

I want to extend the maven runner in the buildAgent to remove some
files before every maven project is run. These are not files in the
working directory so checking the box to clean everything is not
sufficient.

I know this is possible but I was wondering if I could get some
direction on how to do this :)

Thanks
Colin

--
Sergey Anchipolevsky
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


0

That would be great :)

It is pretty simple what I want to do so shouldn't be too much trouble if the api changes in upgrades.

Thanks
Colin

0

Hello Colin,

Here it is.

1. Create your own class extending AgentLifeCycleAdapter (include into classpath
all jars from webapps/ROOT/update/buildAgent.zip).

package com.yourCompany.teamCityPlugin;

import jetbrains.buildServer.agent.*;
import org.jetbrains.annotations.*;

public class PrepareFilesBeforeMavenStarts extends AgentLifeCycleAdapter {
public PrepareFilesBeforeMavenStarts(@NotNull final EventDispatcher]]>
agentDispatcher) {
agentDispatcher.addListener(this);
}

public void beforeRunnerStart(@NotNull BuildRunInfo buildInfo) {
if(!"Maven2".equals(buildInfo.getRunner().getType()))
return; // skip non-Maven builds

File checkoutDir = buildInfo.getCheckoutDirFile(); // checkout directory
(if you need it)

// do whatever you want with files within checkout directory ...
// or in some other place :)
}
}


2. Create build-agent-plugin.xml

3. Make a jar and put build-agent-plugin.xml into its root 4. Put the jar into a directory and add this dir into another zip (I didn't promise the process is simple). Again. This is important -- the zip should contain a directory and the jar should be placed inside this directory. 5. Put this zip into ]]>/webapps/ROOT/update.


Now wait until the agent gets updated automatically.


Hope this works. :)

That would be great :)

It is pretty simple what I want to do so shouldn't be too much trouble
if the api changes in upgrades.

Thanks
Colin

--
Sergey Anchipolevsky
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


0

Hi

I have been trying to implement this but I am running into a few problems.

I compiled the file (had to add utils.jar from server to path as well)

and then put the jar in a zip (I added a lib sub-dir to try as well as that is how the others were done) so the zip file contains the following

/lib/]]>.jar

and the jar has one class and the build-agent-plugin.xml at the root.

I have logging in there but nothing gets output. Every time I drop a new zip into the server folder the agents do get updated with what seems is the correct but I don't think anything ever gets called.

Any more ideas :)

Thanks
Colin

0

Hello Colin,

I'm sorry. I forgot to mention your class must implement interface jetbrains.buildServer.agent.StartableComponent.

Hi

I have been trying to implement this but I am running into a few
problems.

I compiled the file (had to add utils.jar from server to path as well)

and then put the jar in a zip (I added a lib sub-dir to try as well as
that is how the others were done) so the zip file contains the
following

<name of plugin>/lib/<plugin>.jar

and the jar has one class and the build-agent-plugin.xml at the root.

I have logging in there but nothing gets output. Every time I drop a
new zip into the server folder the agents do get updated with what
seems is the correct but I don't think anything ever gets called.

Any more ideas :)

Thanks
Colin

--
Sergey Anchipolevsky
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


0

It Works :)

Thanks

One quick question..... You mentioned the code to get the checked out directory but what is the code to get the agent.home.dir. I tried getting this through the System properties but it is not there.

Thanks again
Colin

0

Hi,
I am tryign to extend Maven Runner in the build agent and I followed the instructions as suggested below. I am using Teamcity4.5.3 and i do not see jetbrains.buildServer.agent.StartableComponent interface available in this version.

Can you please help me with this.

Thanks,
Smitha

0

Hi,
I am trying to extend Maven Runner in the build agent  and I followed the instructions as suggested below. I am using Teamcity4.5.3 and i do not see jetbrains.buildServer.agent.StartableComponent interface available in this version.


Can you please help me with this.


Thanks,
Smitha

0

Hello,

jetbrains.buildServer.agent.StartableComponent interface was created to enforce old build agent components container
to instantiate a component on build agent start.

Since we moved to Spring Framework on build agent side, there is no need to used it, because all components that are
registered in Spring are intialized on application start.

To fix your code, you may simply remove this interface from your code and update components xml.

0

Thanks Eugene for the quick response.
Removing the interface worked.

Thanks,
Smitha


,

0


We're planning to add an ability to extend any build configuration with pre-
and postactions in some future version.





 


Did you add such abilty? If no, can I use several build configurations for such purposes? E.g. set one build configuration with "Command line" runner, another which would be run after the first with "Maven2" runner and the last one with "Command line" runner again for post build actions?

0

Or even you can add ability to make several (not only one) build runner for each build configuration (as we can attach to several VCS configurations from build configuration)

0

Hi,

I upgraded from 4.5.3 to 4.5.4 and now i cannot get the build agent to log any data to the log files. I have set the logging level to DEBUG in teamcity-agent-log4j.xml file.
I see that the build agent upgraded and installed the plugin.

public void beforeRunnerStart(
            @NotNull final jetbrains.buildServer.agent.AgentRunningBuild buildInfo) {
        LOG.info("CleanupPlugin::beforeRunnerStart");
}
I have the same Plugin directory structure as indicated in the documentation.

I am not able to get any further at this point.

Any suggestion/input is very much appreciatated..

Thanks,
Smitha

0

Can you attach the whole class file and your log4j xml file?

0

Hi Pavel,

Please find attached the class file and log4j.xml

Thanks,
Smitha



Attachment(s):
teamcity-agent-log4j.xml
CleanupPluginDummy.java
0

Hi,

Can you please let me know if  more details are required.
I would really appreciate your input regarding this issue.

Thanks,
Smitha

0

Hi Pavel,

I modified the sample Plugin that you had provided at :

http://www.jetbrains.net/devnet/message/5213711


to use the updated API and tried to deploy the same on teamcity4.5.4. It does not seem to log any data to the log files.

Can you please help look into this and let me know what needs to be doen to resolve this.
Thanks,
Smitha

0

It seems your plugin uses wrong event dispatcher: com.intellij.util.EventDispatcher but it should use: jetbrains.buildServer.util.EventDispatcher

Also try to add logging into constructor, just to see whether your class was instantiated or not.

0

Hi Pavel,

Iam now testing the sample plugin that you had provided in this forum at :http://www.jetbrains.net/devnet/message/5213711
which uses the event Dispatcher jetbrains.buildServer.util.EventDispatcher . I added a log statement in its constructor.

I still dont see any message from the constructor in the log file. Looks like its not getting instantiated. But  i have verified that the agent upgraded to pick up the plugin jar file and  installed it on the Build agent.

Please find attached CleanupPluginDummy-src.zip file and CleanupPluginDummy.zip file that is being deployed to TeamCity4.5\webapps\ROOT\update\plugins.

This issue is causing production time problems in our company. Your help to resolve this asap is highly appreciated.

It would be really helpful if you can please post a sample Agent Plugin targetted to work on Teamcity4.5.4

Thanks,
Smitha



Attachment(s):
CleanupPluginDummy-src.zip
0

Since we changed Picocontainer to Spring on the agent side your build-agent-plugin.xml will not be understood by Spring, that is why your plugin is not instantiated.
You should change your build-agent-plugin.xml file to the following:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans default-autowire="constructor">
  <bean />
</beans>

Then you need to ensure this xml file is placed under the META-INF directory in your jar file. You can read more about agent side plugins packaging in our docs: http://www.jetbrains.net/confluence/display/TCD4/Plugins+Packaging

I also created correct zip file from your sources (note that I changed log level in the constructor to info) and it works in my case. Try to deploy it on your agent, you should see log messages.



Attachment(s):
dummycleanupplugin.zip
0

Hi Pavel,

Thanks so much for such a quick response.I really appreicate it.

The changes to build-agent-plugin.xml worked to use Sprign beans instead of pico Container worked.
I am now able to deploy it to the server and see the messages being logged by the Plugin.

Thanks again,
Smitha

0

Hi Pavel,

I was able to see log messages when i deployed the plugin zip file that you had provided. But with the same changes as u had indicated, and with the exact same plugin directory structure as that of dummycleanupplugin.zip. ,
my plugin still does not get instantiated.

Can you please provide the source code used.

Thanks,
Smitha

0

Hi,

Finally got the plugin to Log messages. There was a problem with the arguments being passed to the contructor
Its all set now.

Thanks!
Smitha

0

Please sign in to leave a comment.