Plugin - Build Feature - Artifact Publisher
Hello,
I am trying to implement a TeamCity Plugin, a Build Feature which copies artifacts to a Network Share Release Folder. Specifically..
- Artifacts that are generated by the normal TeamCity "Build Steps" and captured as part of the "Artifacts paths" parameter, are copied by the plugin to an additional network location from where other Enterprise / Deployment tools can access them.
- The plugin should run on the Agent side and not on the Server Side
- I intend on running this step as part of the afterAtrifactsPublished Notification
- Ideally I would like to log all steps of this process to the "Build Log" so that a user can see through the Web Interface exactly what is happening, and where the files are copied to.
- It is important that if any of the artifacts cannot be copied to Release Area, the whole build fails.
I have looked at a number of similar plugins such as Deployer and NetPublisher, and also looked at their source code. I have a number of question regarding how to implement what I am trying to do....
- How do I actually get the Artifacts on the Agent side. For the server side we have the function SRunningBuild.getArtifacts(BuildArtifactsViewMode.VIEW_DEFAULT), but there does not seem to be anything equivalent for the agent side
- How can I log these steps to the Build Log.
- How would I fail the build in case any of the steps fails to complete properly.
- When creating the Plugin, how do I explicitly let it that this is a build feature and not any other type of plugin
- How do I check whether the plugin is enabled / disabled for a build config. We make use of a lot of Templates within our Build Setup and sometimes disable a feature in the inheriting config. I would like to be able to check whether the plugin is enabled for that config.
Apologies if any of these question seem trivial, but this my first TeamCity plugin.
Our environment consist of TeamCity Enterprise 7.1.5 (build 24400) on Windows Server 2008R2.
Thanks in advance for any help,
RG
Please sign in to leave a comment.
Hello,
Please see my answers inline.
On 6/18/2013 18:17, Rishabh Gupta wrote:
If you want to publish artifact to an additional location, then you should take a look at jetbrains.buildServer.agent.ArtifactsPublisher extension. This extension is called automatically when agent is going to publish artifacts somewhere. In fact agent calls all such extensions and our own artifacts publisher is just one of them.
So with help of it you can publish artifacts to some additional location, but you can't prevent publishing by other publishers. See this class as an example of such publisher:
https://bitbucket.org/maximp/teamcity-mirror-plugin/src/631707216e75d2b05b3ad1928b6d1765ff47dd4e/agent/src/jetbrains/buildServer/artifactsMirror/AgentTorrentsManager.java?at=default
You need to obtain an instance of AgentRunningBuild class, see line 103 in the example above. There is a method BuildProgressLogger getBuildLogger() in this object.
See methods message(String), warning(String) and others if you want to log simple text.
You should log build problem with help of BuildProgressLogger, something like:
logger.logBuildProblem(BuildProblemData. createBuildProblem("MY_PROBLEM_ID", "MY_PROBLEM_TYPE", "Some text description"));
You need to extend jetbrains.buildServer.serverSide.BuildFeature class. See example here:
http://svn.jetbrains.org/teamcity/plugins/swabra/branches/Faradi-7.1.x/server/src/jetbrains/buildServer/swabra/SwabraBuildFeature.java
All enabled build features (their parameters) will be sent automatically to the agent. Also their parameters will be resolved if needed (I mean %ref% will be replaced with actual value). So you can obtain all the features of some type on agent with code like this:
final Collection<AgentBuildFeature> features = runningBuild.getBuildFeaturesOfType("feature_type");
Where runningBuild is AgentRunningBuild.
Hope this helps.