tcplugins / tcWebHooks

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

Investigate Mute or Fix Test callback #210

Closed amadeuszpolak closed 1 year ago

amadeuszpolak commented 1 year ago

Hi,

I would like to mark a failed test as Fixed and get some callback to be able re run the build again. Is is possible via tcWebHooks ?

netwolfuk commented 1 year ago

Hi @amadeuszpolak.

tcWebHooks does not currently support this. I see there is a callback that I can use to detect when tests are muted. I'm not sure if this works for "fixed" too.

I can't see another on that page for "fixed tests", so I will try adding a dummy listener for the mute callback and see which events it fires on.

After that we can make a decision on whether we want to add a new build state for this to tcWebHooks.

netwolfuk commented 1 year ago

I've done some testing, and can see a way to subscribe to muted/unmuted tests, but not Mark as Fixed. I have raised a ticket with TeamCity support to see if I have missed something.

https://youtrack.jetbrains.com/issue/TW-79828/Listen-for-Tests-Mark-as-fixed-event-in-OpenAPI

amadeuszpolak commented 1 year ago

That would be also great to have a callback from muted/unmuted tests. But have you seen this ?

In Notification Rules section there is a option to subscribe to "Investigation is updated" option (inside Investigation there is a Fixed tests option), maybe this could be used ?

Screenshot 2023-02-20 at 08 32 48
netwolfuk commented 1 year ago

Hi @amadeuszpolak The teamcity support team replied, and I am already listening for the responsibility changed event.

I have been able to trigger a build from marking the test as fixed. However, I found and fixed a bug that would sometimes stop ResponsibilityChanged from triggering.

Make sure you get the latest build from here. I just pushed the change, so the build should run shortly.

Once that is installed, this is what I did...

  1. Create a new JSON Velocity template that looks like the payload to queue a build.

    {
    "buildType": {
        "id": "${myBuildTypeId}"
    }
    }
  2. Create a token so that your user can trigger a build. This is done in your Profile page. To be extra cautious, just grant the token permission to Run Build for the project you're interested in.

  3. Create a WebHook Parameter in your Project called something like triggerToken, so that you can pass this to the webhook.

    image

  4. Create a WebHook to trigger on Responsibility Changed and choose your new template. Set the URL to be the teamcity server with /app/rest/buildQueue.

    image

  5. Set the webhook to fire on just the build you want.

    image

  6. Set the webhook to use bearer authentication, add the ${triggerToken} and create a Parameter for myBuildTypeId. We need to create this because the template need to know which build to trigger. This the ID of the build, and is usually in the URL of the build. Ignore the filter. I was trying to only trigger on a user interaction, but I have not got that filter working yet.

    image

  7. Mark your Tests as fixed, and the build should be triggered. You should see it executing in the history page.

netwolfuk commented 1 year ago

BTW, the notification is a different mechanism to the one I am able to use. It's the same events, but they have slightly different names. In the notifier it's called Investigation is Updated, but in tcWebHooks it's called Responsibility Changed because that is the name of the event hook I listen for.

I have also added hooks for Test muting on my local branch (not pushed yet) and my callback is called However it doesn't do anything yet. There is quite a lot more work to create a new event and add it to all the templates/rest api/UI/configuration code so I don't have it working yet.

netwolfuk commented 1 year ago

Support for tests muted/unmuted added and released as version 1.2.2 https://github.com/tcplugins/tcWebHooks/releases/tag/v1.2.2