[Solved] How can I resolve parameterized values in a Build Feature plugin?
I have written a Build Feature plugin for TeamCity.
My problem: When a user provides values using build parameters, such as %stash.hostname%, I cannot read its actual value.
That means:
feature.getParameters().get("stash_host")
evaluates to
http://%stash.hostname%:%stash.port%/
But I want it to be whatever the user typed in as a build parameter (http://localhost:81).
In other words, how can I access the resolved value of the user provided parameterized values without performing string replacements myself (to avoid errors and reinventing the wheel)?
In my code, I have tried playing around with SRunningBuild and SBuildFeatureDescriptor, but can't see "stash_host" being properly resolved anywhere.
The user may define build parameters such as this
This is what the user provides in my build feature plugin:
But in my code, all I get is http://%stash.hostname%:%stash.port%/
Any help is appreciated!
Attachment(s):
Screenshot from 2014-01-09 21:47:36.png
Screenshot from 2014-01-09 21:47:12.png
Please sign in to leave a comment.
Hi,
thank you for the effort of writing the plugin.
You can resolve parameters using a ValueResolver (http://javadoc.jetbrains.net/teamcity/openapi/current/jetbrains/buildServer/parameters/ValueResolver.html), which can be acquired from the build:
build.getValueResolver().resolve(value)
where the value is a string which potentially contains references.
Or even better you can acquire BuildFeatureDescriptors like this:
buildType.getResolvedSettings().getBuildFeatures()
in this case all the parameters in the descriptors will be resolved.
Regarding your comment about stale build status you can use a workaround described in http://youtrack.jetbrains.com/issue/TW-22027, e.g. find the finished build using:
BuildHistory.findEntry(runningBuildId)
the finished build has an up-to-date status.
Also we have a similar plugin which publishes status to Stash and Gerrit Code Review: https://github.com/JetBrains/commit-status-publisher. Probably in a future we will also add Github status reporting. Please give it a try. Any feedback or contributions are appreciated.
Thanks, I have used
And it is working just fine.
Also thanks for the stale build status workaround, I will try it out!
Has this behaviour changed between 8.1(.0) and 8.1.1?
My plugin was using build.getValueResolver().resolve to evaluate build feature parameters that contined %teamcity.build.branch% and %teamcity.build.id%. In 8.1 it was successful, but in 8.1.1 and later those parameters resolve to <default> and -1 respectively, regardless of the actual build branch and id.
Also, how can getting the features resolved fomr the BuiltType work, when paramters can be bulid-specifc (like %teamcity.build.id%)?
Thanks,
Charles.
EDIT: I raised TW-38162 to cover this issue
buildType.getResolvedSettings().getBuildFeatures() does not work when user starts build with non-default parameters valies. Build parameters have default values from build configuration.
Have you any ideas how to get actual values?