Howto get beginLine and endLine of VCS changes in BuildProcessAdapter extension

I'm writing a plugin and I need the line numbers of the changes (in the "after" file).

It looks like I can get that from SBuild.getChanges().getChanges().getContentAfter() and getContentBefore() (and then diffing them).

However, the only object references that were passed in are AgentRunningBuild and BuildRunnerContext.  I don't see an available SBuild reference in either of them.

Is there a way to get a reference to an SBuild object?

note: I'm getting the AgentRunningBuild and BuildRunnerContext references from extending AgentBuildRunner and implementing createBuildProcess(@NotNull AgentRunningBuild runningBuild, @NotNull BuildRunnerContext context) (and then passing them in to my BuildProcessAdapter extension).  I know it's standard to not directly extend AgentBuildRunner, but the BuildServiceAdapter route doesn't work for me.

Also, if there's an easier way to get the line numbers of the changes than manually diffing getContentBefore and getContentAfter, please let me know.



Comment actions Permalink

Hi Rob,

SBuild and the file contents API belong to the TeamCity server-side. There is no easy way to get file history on the agent side.

I can think of several approaches here:
a. Do the necessary calculations on the server side and then pass the results onto the agent as build's parameters
b. Query server for the file content's using REST API or other server HTTP requests, but options here are quite limited
c. do not rely on TeamCity to get the file content, use agent-side checkout and VCS client to do that

Comment actions Permalink

Hey Yegor,

Thanks for the reply.

- Not quite sure how to hook into the server to do the work there.  The examples I can find are about the RunType/Config.

- I wasn't able to find what I need in the REST api.

- I was hoping I didn't have to duplicate the VCS work that's already been done.  Literally, the Changes tab has everything I need!  It seems like such a waste reinventing that wheel.  But I guess if there are no other options...:)  Any chance this will be exposed in the future?  Having access to the VCS change "artifacts" seems useful.


Comment actions Permalink


So far the logic related to file content and diffs seems to be better implemented on the server-side.

Could you detail what exactly do you want to implement and why you need the diff on agent?

Comment actions Permalink

Of course.

Just to be clear though, I absolutely agree it's better implemented on the server-side.  I'm not suggesting the implementation be moved to the agent-side, I'm suggesting access to the results (i.e., the details of what was changed, not just the summary) would be useful on the agent-side.

I'm would like to write a plugin that ensures changes are covered by unit tests.  In order to do that, I need a) the lines that were changed and b) the lines that are covered.  

I currently have b.  I just need a.


Please sign in to leave a comment.