Get trigger's rule comment's REGEX and assign it to a variable

Suppose I have a regular expression in my build trigger: if my comment contains something like #BUILD 1.5.9# I want to start a build and have 1.5.9 as context variable (parameters?) since during the build pipeline I could use that variable and drop the artifacts inside a directory release1.5.9 .

 

Is this possible?

0
1 comment

You could do it if you stored the regex pattern as a parameter, which is referenced in both the build trigger and an early build step (assuming you're talking about VCS comments i.e. https://confluence.jetbrains.com/display/TCD10/Configuring+VCS+Triggers#ConfiguringVCSTriggers-TriggerRulesExample)

The build step would need to query REST for a list of the changes: /app/rest/changes?locator=build:(id:000000)

Then would have to iterate through each change and get the comment text from Perforce, Git or whatever - attempting to match it against the regex pattern. It could then update a second parameter according to regex capture groups, which would be used in the artifact gather.

So it's doable - but not the cleanest!

 

You would be better off specifying the version as either a first-class parameter which is specified on each build (through the run popup), or one based on the change ID through %build.vcs.number%. Alternatively your version could live in a text file on your VCS which would be used by TeamCity to set a parameter directly.

0

Please sign in to leave a comment.