Date as build number
Hello,
I'm trying to code a plugin which replaces the "" pattern by the date of the build.
Here is what I've done :
-
package com.sncf.gl.apps.teamcity.plugins.datebuilnnumber; import java.text.SimpleDateFormat; import java.util.Date; import jetbrains.buildServer.serverSide.BuildServerAdapter; import jetbrains.buildServer.serverSide.SBuildServer; import jetbrains.buildServer.serverSide.SRunningBuild; import com.intellij.openapi.diagnostic.Logger; public class DateBuildNumber extends BuildServerAdapter { private final static Logger LOG = Logger.getInstance(DateBuildNumber.class.getName()); private static final String DATE = "";
// Constructor
public DateBuildNumber(SBuildServer aBuildServer)
{
System.out.println( "### DateBuildNumber adding listener=" + this );
LOG.info("### DateBuildNumber adding listener=" + this);
// Register with TC
aBuildServer.addListener(this);
}
public void buildStarted(SRunningBuild build)
{
String buildNumber = build.getBuildNumber();
// Logging
System.out.println("### DateBuildNumber plugin : buildStarted");
LOG.info("### DateBuildNumber plugin : buildStarted");
// If the build number contains the {date} pattern we replace it by the current date.
if(buildNumber.lastIndexOf(DATE) > -1)
{
build.setBuildNumber(buildNumber.replace(DATE, createBuildNumber()));
}
else
{
System.out.println("### DateBuildNumber plugin, no {date} pattern found");
LOG.info("### DateBuildNumber plugin, no pattern found");
}
}
public String createBuildNumber()
{
Date currentBuild = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmssZ");
return sdf.format(currentBuild);
}
}
-
And here is my build-server-config.xml file :
]]>
-
The problem is I don't exactly understand how to register the plugin in TC.
I've watched stdout logs and there's nothing about my plugin?
Does someone can help me?
Regards,
Xavier
Edited by: Xavier Seignard on Oct 7, 2008 11:02 AM
Please sign in to leave a comment.
You should create jar file with META-INF folder containing your spring xml file. The easiest way to check that your plugin is actually working is to put this jar into the WEB-INF/lib folder and restart server.
In TeamCity 4.0 it is possible to keep plugins outside of TeamCity installation directory. For this you can create zip file with name ]]>.zip and put your jars there. Then you can copy this zip to the .BuildServer/plugins folder and restart server.
--
Pavel Sher
Thanks,
I've already did it.
By the way, it works fine now. Don't know what was wrong, because I didn't changed anything ?!?!
I would like to share this really simple plugin which can be useful for some people, how can I do it?
Regards,
Xavier
Could you please register in our confluence: http://www.jetbrains.net/confluence/
We then can create a page for your plugin and grant you rights for this page.
--
Pavel Sher
It's done!
Xavier,
Here you are: http://www.jetbrains.net/confluence/display/TW/DateBuildNumber
You should be able to modify the page now.
--
Best regards,
Yegor Yarko
Project Manager (TeamCity)
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
Sorry but I can't modify it?!
Xavier,
Sorry, it seems the permissions configuration in Confluence is a bit trickier then it seemed to be.
We will try to resolve this. For the time being you can send me the content for the page so I can paste it.
Hi,
I still can't do anything in confluence!
Regards
Xavier
PS : Thanks for your sprint on Clearcase!
Xavier,
Sorry, for the time being we did not found a suitable way to grant permissions for editing a single page in a space.
I have sent you an email some time ago with suggestion to put the content in your personal space and I will then include the page into or space.
Is this suitable for you?
--
Best regards,
Yegor Yarko
Project Manager (TeamCity)
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
done
I hope it could be useful for someone.
Regards,
Xavier
Thank you, Xavier.
I've included your page into the corresponding plugin page:
http://www.jetbrains.net/confluence/display/TW/DateBuildNumber
I've made a dedicated page, it's much easier.
http://www.jetbrains.net/confluence/display/~bigx/Date+Plugin
Regards,
Xavier
That page (http://www.jetbrains.net/confluence/display/TW/Date+Build+Number) seems to be broken.
Dirk,
Seems some Confluence permissions problem. For now I copied the page content inplace.
You can also consider using Groovy Plug plugin to get the build start date.