Closed Peterosh closed 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.
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
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.
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
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.
Thank you very much
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
The parameters on my test build look like this in the Teamcity UI
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.
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()
.
It's really cool.it worked.Thank you very much
Great. I'll close this issue
Hello. How do I get the parameters of dependent projects .for example ${dep. *. Build. VCS. Number}