Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variables not populated in the Started event #102

Closed
dgilman opened this issue Apr 18, 2018 · 10 comments
Closed

Variables not populated in the Started event #102

dgilman opened this issue Apr 18, 2018 · 10 comments
Labels
available in alpha or beta release item is released in a "pre-release" version ready for testing. waiting for release
Milestone

Comments

@dgilman
Copy link

dgilman commented Apr 18, 2018

I am working on TeamCity templates for tcWebHooks and I have a branch build template defined like so:

{
    "markdown": "[${projectName}](${rootUrl}/project.html?projectId=${projectExternalId}) :: [${buildName}](    ${rootUrl}/viewType.html?buildTypeId=${buildExternalTypeId}) | [${branchDisplayName} ${substr(build.vcs.number,0,7,32)}](${buildStatusUrl}&tab=buildChangesDiv) | [build #${buildNumber}](${buildStatusUrl}) | **${capitalise(buildStateDescription)}**"
}

The variable ${substr(build.vcs.number,0,7,32)} gets defined in the Started hook as ??? but is correctly defined in later hooks:

[2018-04-18 16:40:54,698]   INFO -   jetbrains.buildServer.SERVER - WebHookListener ::  :: WebHook triggered : https://blahblah using format jsontemplate returned 204 No Content 
[2018-04-18 16:40:54,698]  DEBUG -   jetbrains.buildServer.SERVER - WebHookListener :: :doPost :: content dump: {
    "markdown": "[test proj](http://localhost:8111/project.html?projectId=TestProj) :: [test branch proj](http://localhost:8111/viewType.html?buildTypeId=TestProj_TestBranchProj) | [imaci5 ???](http://localhost:8111/viewLog.html?buildTypeId=TestProj_TestBranchProj&buildId=54&tab=buildChangesDiv) | [build #36](http://localhost:8111/viewLog.html?buildTypeId=TestProj_TestBranchProj&buildId=54) | **Started**"
} 
[2018-04-18 16:40:56,054]  DEBUG -   jetbrains.buildServer.SERVER - WebHookListener :: :doPost :: content dump: {
    "markdown": "[test proj](http://localhost:8111/project.html?projectId=TestProj) :: [test branch proj](http://localhost:8111/viewType.html?buildTypeId=TestProj_TestBranchProj) | [imaci5 72123ab](http://localhost:8111/viewLog.html?buildTypeId=TestProj_TestBranchProj&buildId=54&tab=buildChangesDiv) | [build #36](http://localhost:8111/viewLog.html?buildTypeId=TestProj_TestBranchProj&buildId=54) | **Loaded Changes**"
} 

I'm pretty much just copying the Slack templates so I am surprised to see this. Is this expected behavior and is the Slack template doing the same thing?

@netwolfuk
Copy link
Member

netwolfuk commented Apr 18, 2018

Hi @dgilman

Yes I noticed that with the slack one this week. It would be related to #26.

@netwolfuk
Copy link
Member

I just checked the slack messages. The loaded changes event does have the commit and branch name correctly populated (eg, master rather than <default>)

@dgilman
Copy link
Author

dgilman commented Apr 18, 2018

I've created a loaded changes hook that says "Started" as a workaround which will work and I'm ok with upstreaming (if you're ok with merging).

I'm coming to Spark from Slack and the tcSlackBuildNotifier plugin which fired a Started message as soon as the build started (it seems) and was able to correctly figure out the branch and commit ID. I don't really know the TeamCity API at all but it looks like it just listens to buildStarted and not changesLoaded.

@netwolfuk
Copy link
Member

I'll have a look at Pete's code and see what he's doing. It's actually a fork of mine from about 5 years ago.

@netwolfuk
Copy link
Member

BTW. Have a look at the tcWebHooksTemplates project on GitHub which I've be working on this week for a way to share templates.

@netwolfuk
Copy link
Member

@netwolfuk
Copy link
Member

I installed the tcSlackNotifier plugin and have noticed the following behaviour:

If there are no changes, the start event does not list anything.
image

If there are changes, then it builds a nice commit message
image

This behaviour is consistent with the tcWebHooks Legacy JSON payload format. To test this, I just created a legacy json webhook and pointed it at http://localhost:8111/webhooks/endpoint.html
No changes:
image

Changes:
image

However, when I built the Slack template, I used the TeamCity defined parameter because:

  1. The webhook template templating language has no support for conditionals.
  2. The changes object does not serialise to JSON correctly (See Changes variable does not serialize to Json #98)
  3. If a build ran with no changes, it wouldn't give any indication of which revision it was built against anyway. This is consistent with the behaviour of the Slack Notifier on start.

I will add some more payload variables to the standard set to give us a bit more info at start. However, in the case where there is a build run without any changes, this will still be blank.

Off the top of my head the following would be useful.

  • buildHasChanges: boolean
  • buildChangesComment: string
  • buildChangesUsername: string
  • buildChangesVersion: string
  • buildChangesFileCount: int

These would give the most recent change, although from screenshots, it looks like the tcSlackNotifier lists all contributing changes, not the latest.

However, without conditionals in the template it wouldn't solve our problem yet.

So to get around that, we could have a macro (like the substring one), at which point it starts to get messy, and I should really just finish the work to support the Velocity template language.

@netwolfuk
Copy link
Member

I need to revisit this in 1.2, as most of these issues should be mitigated with conditionals in velocity templates.

@netwolfuk netwolfuk added this to the v1.2 milestone Aug 8, 2020
@netwolfuk
Copy link
Member

Hi @dgilman. Please see comments on the end of #26
I've added a feature to resolve variables early in 1.2.0-alpha8

@netwolfuk
Copy link
Member

1.2.0-alpha8 finally released.

@netwolfuk netwolfuk added waiting for release available in alpha or beta release item is released in a "pre-release" version ready for testing. labels Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
available in alpha or beta release item is released in a "pre-release" version ready for testing. waiting for release
Projects
None yet
Development

No branches or pull requests

2 participants