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

Dependent projects Parameters #197

Closed Peterosh closed 2 years ago

Peterosh commented 2 years ago

Hello. How do I get the parameters of dependent projects .for example ${dep. *. Build. VCS. Number}

netwolfuk commented 2 years ago

Hi @Peterosh

Which version of tcWebHooks are you running? Which template engine is your template using? Standard or Velocity.

For standard, I think I convert all the dotted names to with an underscore instead. Eg, ${dep_mybuild_Build_VCS_Number}.

For Velocity I'd need to check, but I'm pretty sure they're there too somehow.

Peterosh commented 2 years ago

Tcwebhook version is 1.1.374.403 I used a custom template. Can I use a wildcard? Such as ${dep_ * _Build_VCS_Number} I've tried. He's not working

netwolfuk commented 2 years ago

It's not possible to use a wildcard sorry. What are you wanting to achieve? I might be able to give you some other suggestions.

Peterosh commented 2 years ago

I want to use a set of templates for all project notifications. But they dependent on different projects. You know, different project dependencies, variables are different. For example, dep.pro1.build.vcs.number dep.pro2.build.vcs.number I want to use dep.*.build.vcs.number

netwolfuk commented 2 years ago

I think if there is anything I can try it will be on a velocity template as we can loop over lists and use conditionals.

I'll try some things over the weekend and come back to you.

Peterosh commented 2 years ago

Thank you very much

netwolfuk commented 2 years ago

Hi @Peterosh

I've written an example template which uses Velocity logic to loop over the parameters on the build. You will need to install one of the 1.2.0 alpha releases of the plugin and rest api, so that you can use the Velocity template engine. Also, don't forget to choose Actions/Edit to change your template type to JSON Velocity Template

image

The parameters on my test build look like this in the Teamcity UI image

With Velocity, we have full programming access to the objects in a build. Here is an example of looping over the parameters of the $build object.

#foreach ($paramEntry in $build.parametersProvider.all.entrySet())
#if ($paramEntry.key.startsWith("dep.") && $paramEntry.key.endsWith(".build.vcs.number") && !$paramEntry.key.endsWith(".system.build.vcs.number"))
${paramEntry.key} : ${paramEntry.value}
#end
#end

When I preview the template in the template editor, I can see the values being found and displayed. image

netwolfuk commented 2 years ago

BTW, the ${build] object in a Webhook Template is a TeamCity SBuild class. You can therefore access any methods on the SBuild class as defined in the TeamCity javadocs for https://javadoc.jetbrains.net/teamcity/openapi/current/jetbrains/buildServer/serverSide/SBuild.html

With Velocity, you can access an object item by name if the method starts with get, eg. $build.parametersProvider will call the method getParametersProvider(). If a method does not start with get, then you can still call it but you need to call the method name explicitly. For example the method above entrySet().

Peterosh commented 2 years ago

It's really cool.it worked.Thank you very much

netwolfuk commented 2 years ago

Great. I'll close this issue