How can I determine the build URL from within a Notification Plugin?

I am writing a Notification plugin and I wish to send, as part of the outgoing info, the URL of the build page that is running.  

All the methods in a Notificator give an SRunningBuild.  So to be specific, how would I construct this URL given an SRunningBuild?

    http://localhost:8111/viewLog.html?buildId=12&tab=buildResultsDiv&buildTypeId=bt2


I would probably be able to construct the URL but I don't know how to get the server name (localhost:8111, somethingelse:8080).  I can figure out the buildId and the buildTypeId from the sRunningBuild properties (sRunningBuild.getBuildNumber()).  But the base URL eludes me!

I see that a getRootURL method exists in SBuildServer.  But I don't know how to get to SBuildServer from the Notificator.  

Any ideas would be appreciated.  

1 comment
Comment actions Permalink

I had done a lot of searching before posting and I did a lot of searching afterwards.  I finally found an answer.

First, in the constructor of your class, ask for a WebLinks.

    public MyNotificator(NotificatorRegistry notificatorRegistry, WebLinks webLinks)

Then, you can use it to get various URLs:

Get the root URL of the server:


    webLinks.getRootUrl()

Get the URL of the build page:

    webLinks.getViewLogUrl(sRunningBuild)



And that was it.  This enables you to get various TeamCity URLs from a server side plugin.

I didn't know about the WebLinks but it makes sense, it makes me wonder what else I could ask for in the constructor!

0

Please sign in to leave a comment.