tcWebHooks icon indicating copy to clipboard operation
tcWebHooks copied to clipboard

Copy (or move) webhook when build copied (or moved)

Open danielwellman opened this issue 10 years ago • 11 comments

We are using tcWebHooks version 0.9.27.61 on TeamCity 9.0.2 build 32915 on several projects; thank you for creating this plugin!

I moved a build configuration from one project to another and noticed that the WebHook was removed after the move. In the TeamCity server log, we see this event confirming success of the move:

[2015-07-27 21:56:39,926] INFO - tbrains.buildServer.ACTIVITIES - "Old Project :: My Build Configuration {id=..., internal id=...}" was moved from "New Project :: My Build Configuration" by "'user' (...) {id=...}"

We later re-added the WebHook to the build configuration and things work as expected.

Do you know of any way to preserve the build configuration's WebHooks when moving to different projects?

danielwellman avatar Jul 28 '15 19:07 danielwellman

Thanks for your comments. I can't say I've ever tried moving a build before. Can you tell me a bit more about your webhook configuration?

Was the webhook configured against:

  • That build only?
  • Or against the project?
  • Or against a parent project?

By that I'm meaning did you customise anything on the builds tab of the webhook ui form? Or if you could post the content of the configuration file called plugin-settings.XML (I think it's called that) before and after the change? TeamCity should be able to show you versions of the file. The webhook settings are stored in ~~.BuildServer/config/your_project_name/plugins/plugin-settings.xml~~ .BuildServer/config/projects/your_project_name/pluginData/plugin-settings.xml

netwolfuk avatar Jul 28 '15 20:07 netwolfuk

Oh. Don't forget to remove the URL of the webhook config if it contains your api key or something sensitive.

netwolfuk avatar Jul 28 '15 20:07 netwolfuk

Can you confirm whether the webhook existed in either project after the move? You appear to only have added it back in once (trying to glean that from your words). Was that to the new project or the old project? I've only been able to reproduce your issue by saying that moving a build does not move the webhook with it. It still exists in the old project. The tests I have done are moving a build from one project to a sub-project. The build I moved was one of two builds in the original project. I did have to re-create the webhook in the new project, but it did still exist in the old one too.

netwolfuk avatar Jul 29 '15 10:07 netwolfuk

Hi, thanks for following up so quickly and for the detailed instructions - they were very helpful in finding the data.

The webhook is configured for the specific build, but I'd like to check to make sure I'm using the correct terminology. I can go to my build configuration page and click on the "WebHooks" tab. On this page I see "There are no WebHooks configured for this project." and below I see "There are 1 WebHooks for this specific build."

I looked at the old project and the old WebHook is still there. We had to add it to the new project, so I think you have summarized it correctly as "Moving a build does not move the webhook with it. It still exists in the old project."

Here's the change in the project plugin settings when we re-added it (it's the same as still exists in the old project):

<?xml version="1.0" encoding="UTF-8"?>
<settings>
  <webhooks enabled="true">
    ...
    <webhook url="http://my-server.com:8080/my-action" enabled="true" format="json">
      <states>
        <state type="buildFinished" enabled="true" />
        <state type="buildBroken" enabled="false" />
        <state type="responsibilityChanged" enabled="false" />
        <state type="buildStarted" enabled="false" />
        <state type="beforeBuildFinish" enabled="false" />
        <state type="buildInterrupted" enabled="false" />
        <state type="buildFixed" enabled="false" />
        <state type="buildSuccessful" enabled="true" />
        <state type="buildFailed" enabled="false" />
      </states>
      <build-types enabled-for-all="false" enabled-for-subprojects="false">
        <build-type id="bt123456" />
      </build-types>
    </webhook>
  </webhooks>
...
</settings>

danielwellman avatar Jul 29 '15 22:07 danielwellman

Yes, it looks like we are seeing the same issue. Thanks for raising it. I had not really considered this use case before.

I presume I can hook into the the move events so that I am notified when a build is copied or moved by TeamCity. Then I could run some logic to see if the build moved or copied has a specific webhook configured. The question then arises: What should happen when a build is copied or moved and there are webhooks configured for that project. I guess it depends on:

  • Whether it's moving to a subproject and the webhook has sub-project enabled.
  • Whether the exact same webhook already exists in the new project.
  • Probably some other edge cases to be considered. I'll have a think about it. I'll leave the ticket open and will update when I can.

netwolfuk avatar Jul 30 '15 05:07 netwolfuk

These look promising for build or project moves. Copying might be trickier.


class jetbrains.buildServer.serverSide.BuildServerAdapter {

  public void projectMoved(@NotNull final SProject project, 
                           @NotNull final SProject originalParentProject) {
  }

  public void buildTypeMoved(@NotNull final SBuildType buildType, 
                             @NotNull final SProject original) {
  }

}

netwolfuk avatar Aug 02 '15 01:08 netwolfuk

Yes, those do look promising. If it helps, I don't have a strong use case for copying projects right now; build type moves would be enough for my needs.

danielwellman avatar Aug 04 '15 00:08 danielwellman

Understood. I just think that when copying a build, one would expect the same behaviour between the two commands. I've marked this as milestone 1.2 The templating changes are earmarked for 1.1 (this month I hope), and then 1.2 can be explored. I'll raise a ticket with teamcity support in case there is a hook I've missed for getting copy events.

netwolfuk avatar Aug 04 '15 10:08 netwolfuk

Works for me, thank you!

danielwellman avatar Aug 05 '15 01:08 danielwellman

The ever helpful @pavelsher has replied back. Copy seems "possible" through an internal API call. https://youtrack.jetbrains.com/issue/TW-42143 I will have a think about how comforable I am with that approach.

netwolfuk avatar Aug 10 '15 21:08 netwolfuk

Hi @danielwellman

Assuming you're still interested in this, I have been thinking about a few scenarios: The following would need to be assessed for every webhook configured in the current project or any parent.

  • Build is moved to a sub-project Webhook is configured for all builds and sub-projects No change required

  • Build is moved to another project WebHook is configured for all builds Webhook should be copied to other project and enabled for that build only

  • Build is moved to another project WebHook is configured for just that build WebHook should be copied to new project and enabled for that build only. Webhook should be left in old project, but will have no enabled builds

  • Build is copied to a sub-project Webhook is configured for all builds and sub-projects No change required

  • Build is copied to another project WebHook is configured for all builds Webhook should be copied to other project and enabled for that build only

  • Build is copied to another project WebHook is configured for just that build WebHook should be copied to new project and enabled for that build only. Webhook should be left in old project and remain enabled for original build

netwolfuk avatar Sep 12 '20 19:09 netwolfuk