Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
danielwellman opened this issue Jul 28, 2015 · 11 comments
Open

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

danielwellman opened this issue Jul 28, 2015 · 11 comments
Labels
Milestone

Comments

@danielwellman
Copy link

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?

@netwolfuk
Copy link
Member

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
Copy link
Member

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

@netwolfuk
Copy link
Member

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.

@danielwellman
Copy link
Author

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>

@netwolfuk
Copy link
Member

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 netwolfuk changed the title Webhook lost after build configuration moved Copy (or move) webhook when build copied (or moved) Jul 30, 2015
@netwolfuk netwolfuk added bug and removed enhancement labels Aug 1, 2015
@netwolfuk netwolfuk added this to the 1.2 milestone Aug 1, 2015
@netwolfuk
Copy link
Member

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) {
  }

}

@danielwellman
Copy link
Author

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.

@netwolfuk
Copy link
Member

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.

@danielwellman
Copy link
Author

Works for me, thank you!

@netwolfuk
Copy link
Member

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 netwolfuk added this to In Progress in Release Milestone 1.2 Dec 6, 2017
@netwolfuk netwolfuk moved this from In Progress to To Do in Release Milestone 1.2 Dec 6, 2017
@netwolfuk
Copy link
Member

netwolfuk commented Sep 12, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants