tcplugins / tcWebHooks

WebHooks plugin for Teamcity. Supports many build states and payload formats.
https://netwolfuk.wordpress.com/category/teamcity/tcplugins/tcwebhooks/
156 stars 30 forks source link

Allow to select subprojects in webhook configuration #117

Open alexkaos87 opened 6 years ago

alexkaos87 commented 6 years ago

Expected Behavior

Using nested subproject definitions, I would like to define a webhook configuration at the top (e.g. _Root) and select only nested project that we require. In this way, we can reduce duplications in different subproject that use same channel/url

Current Behavior

No possibility to select nested subprojects; only one level of nesting is allowed to share same configuration

netwolfuk commented 6 years ago

Out of interest, how many levels do you have? We typically have about 3 projects deep as maximum, so I am just trying to determine what the ux might look like.

alexkaos87 commented 6 years ago

at the moment, bigger nested case on our sistem includes 5 level of nested projects

huehnerlady commented 4 years ago

With our system it is up to 3. Is there any update on this issue?

We are facing the same problems, we want to add a webhook at the root level. Currently we cannot test this as the subprojects are not found at all. Is there any way to get a workaround for the problem apart from adding the webhook in over 50 Projects?

image image

We are currently using TeamCity 2017.2.2

netwolfuk commented 4 years ago

Hi @huehnerlady It looks like you're trying to setup a webhook in a project that has no builds configured. Or are you adding a webhook at the root level? For me, the root level finds all recent builds. Can you please open the developer console in your browser, and then open the webhook dialog? It should make a rest request to builds? and load the list of recent builds in all sub-projects.

image

netwolfuk commented 4 years ago

Just try clarify. @huehnerlady Do you want to have the webhook configured for all sub projects, or do you want to be able to select specific projects, or even specific builds within projects?

netwolfuk commented 4 years ago

Assuming we can get this list of builds working for you, we should be able to configure a filter to prevent the webhook from triggering on certain scenarios.

I'll do some testing and provide an example configuration.

netwolfuk commented 4 years ago

https://github.com/tcplugins/tcWebHooks/wiki/Applying-Filtering-Criteria-To-WebHook-Execution

Currently they need to be edited in the config file, but editing in the UI is on the road map for the 1.2 release.

netwolfuk commented 4 years ago

I have been able to use filters to conditionally trigger a webhook for a specific build and/or project. This is what I did:

  1. Edit TeamCity parameters in the _Root project. For me, the URL was /admin/editProject.html?projectId=_Root&tab=projectParams
  2. Create a Parameter with the default setting. I created a Parameter called webhook.my_webhook_enabled, and set the default value to false image Note: Any parameter prefixed with webhook. will have the prefix removed when added to the webhook payload. It will therefore be in the payload as simply my_webhook_enabled
  3. Create your webhook configuration in the WebHook UI. You can skip this step if you already have a webhook configured.
  4. Go into Administration | Diagnostics | Browse Data Directory and edit the plugin-settings.xml for the project you created the webhook in. Mine was at config/projects/_Root/pluginData/plugin-settings.xml because I created it in the _Root project.
  5. Find your webhook configuration, and add a filter configuration to check for the required parameter. This is what mine looked like: image The code block I added is:
      <trigger-filters>
        <filter value="${my_webhook_enabled}" regex="^true$" enabled="true" />
      </trigger-filters>

    If the above matches, the webhook will trigger, otherwise it will be skipped.

  6. Trigger a build and see that it is skipped in the webhook history. Navigate to Administration | WebHooks and click the number for "Skipped Events". For me the URL is /webhooks/history.html?view=skipped
  7. You should an event like this, indicating that the webhook was skipped. image
  8. To enable this webhook for certain builds or whole projects, override the Parameter value in a Build or Project configuration. I created a Build Parameter called webhook.my_webhook_enabled, and set the default value to true.
  9. Trigger a build for a build that will have this new parameter defined. You should see the webhook sent in the history of "Succesful Events". For me the URL is /webhooks/history.html?view=ok image

You can go into any build or project and define this parameter to override it. If the parameter is not defined, it will inherit the one from the _Root project.

netwolfuk commented 4 years ago

Note: It appears that using the test button in the webhook UI ignores the filter match, and sends the webhook anyway. This is a bug, although you can't actually see that, due to the builds list not being populated correctly.

@huehnerlady Do you have your teamcity located at a different context in Tomcat? eg, something like http://your_server/teamcity/ Perhaps that is why the build list is not loading correctly. Can you please send a screen shot of the browser console trying to load the builds?locator=... URL?