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

Added to queue event: null buildId #159

Closed
nrukavkov opened this issue Jun 12, 2020 · 17 comments
Closed

Added to queue event: null buildId #159

nrukavkov opened this issue Jun 12, 2020 · 17 comments
Labels
available in alpha or beta release item is released in a "pre-release" version ready for testing. enhancement waiting for release
Milestone

Comments

@nrukavkov
Copy link

nrukavkov commented Jun 12, 2020

Hello @netwolfuk 😋

Current Behavior

Event 'added to queue' generates webhook without buildid. We were expecting to be able to change a tag on a build. But it is not possible, because webhook's payload has a null value in buildId. Is it possible to have some trick and pass a build value?

Your Environment

  • tcWebHooks Version: tcWebHooksPlugin 1.2.0-alpha.6
  • TeamCity Version: TeamCity Professional 2020.1 (build 78475)
@nrukavkov nrukavkov changed the title Added queue: null buildId Added to queue event: null buildId Jun 12, 2020
@netwolfuk
Copy link
Member

I don't believe an ID has been assigned at this point. My understanding is that the ID is assigned at the started event.

@nrukavkov
Copy link
Author

I don't believe an ID has been assigned at this point. My understanding is that the ID is assigned at the started event.

🤔 If you use API to add a new build to queue, teamcity returns build ID and other additional information. And it doesn’t matter has it been started right now or just was added to a queue.

Here is my simple part of PowerShell code which I use to start builds and get their IDs:

function Add-ToTeamcityQueue($baseUrl, $buildTypeId, $teamcityEnvVariables , 
$teamcityComment, $username, $password, $tags) {
    $baseUrl = $baseUrl + '/httpAuth/app/rest/buildQueue'
    $payload = @{ buildType = @{ id = "$buildTypeId" }; comment = @{ text = "$teamcityComment" } ; tags = @{ tag = $tags} ; properties = @{property = $teamcityEnvVariables} } 
       
    Send-HttpRequest "$baseUrl" $username $password 'POST' ($payload | ConvertTo-Json -Depth 3)
}
$response = Add-ToTeamcityQueue $($project.BaseUrl) $($project.ProjectId) $preparedParameters $teamcityComment $TeamcityUsername $TeamcityPassword @(@{ name = $DestinationBranch})
Write-Host "$type build id: " $response.id

$response.id has an ID of every build

@netwolfuk
Copy link
Member

There is an item id.
http://javadoc.jetbrains.net/teamcity/openapi/current/jetbrains/buildServer/QueuedBuild.html#getItemId--

Is that id the same as the id of the build when it's running/finished?

@netwolfuk
Copy link
Member

netwolfuk commented Jun 12, 2020

Is the buildTypeid something like bt11 ? If so that is the internal id of the build configuration, not the build instance

Sorry. Ignore that. That is part of your payload, and I misread it on my phone.

@netwolfuk
Copy link
Member

netwolfuk commented Jun 12, 2020

@netwolfuk
Copy link
Member

This ticket implies that promotionId and buildId are the same for TeamCity 9.0 and above.

I'll do some testing to confirm.

netwolfuk added a commit that referenced this issue Jun 13, 2020
@netwolfuk
Copy link
Member

netwolfuk commented Jun 13, 2020

I've committed a change that copies the promotionId into the buildId field in the Queued webhook events (queue and de-queue).
After it finishes building it will be available to download from here. Just login as a guest if you don't have a Jetbrains account.

@nrukavkov
Copy link
Author

I will take a look on it on Monday. Thank you.

@netwolfuk
Copy link
Member

Cool. If I get a chance I'll do some more testing too.

@netwolfuk
Copy link
Member

I have a webservice that receives a LegacyJson webhook request for every build event in my development environment. I can confirm that for every buildAddedToQueue event, there is now a buildId set. Previous to yesterday, it was null.

I didn't have any previous buildRemovedFromQueue events, but testing that now they are also showing a buildId. From the 17 builds that ran in the last 24 hours, all the buildIds appear to match so I am assuming that the promotionId and the buildId are the same value.

@netwolfuk
Copy link
Member

I'd appreciate it if you could keep an eye on the buildId, and let me know if they ever don't match for the other events in the build. However from my little bit of testing, and that comment in the youtrack ticket, I think it should be fine.

@nrukavkov
Copy link
Author

nrukavkov commented Jun 14, 2020

No problem! I guess everything will be fine. I've tested your fix on a newly installed teamcity and it works.

Just one case I want to show you. The payload looks like this when there are no agents to start. But I suppose that is fine. You can't definitely know buildId.

{
        "embeds": [
            {
                "title" : "Been Added To The Build Queue : test build build #${buildNumber}",
                "url" : "http://localhost:8111/viewLog.html?buildTypeId=bt1&buildId=lastFinished",
                "author" : {
                    "name" : "TeamCity",
                    "url" : "http://localhost:8111/",
                    "icon_url" : "https://raw.githubusercontent.com/tcplugins/tcWebHooks/master/docs/icons/teamcity-logo-48x48.png"
                },
                "fields": [
                    
                    { "name" : "Status", "value" : "${buildStatus}", "inline": false },
                    { "name" : "Project Name", "value" : "[test](http://localhost:8111//project.html?projectId=Test)", "inline": true },
                    { "name" : "Build Name", "value" : "[test build](http://localhost:8111//viewType.html?buildTypeId=Test_TestBuild)", "inline": true },
                    { "name" : "Commit", "value" : "[UNRESOLVED](http://localhost:8111/viewLog.html?buildTypeId=bt1&buildId=lastFinished&tab=buildChangesDiv)", "inline": true },
                    { "name" : "Triggered By", "value" : "admin", "inline" : true },
                    { "name" : "Agent", "value" : "${agentName}", "inline" : true }
                ]
            }
        ]
    }

None the less I'll get you to know If something goes wrong.

@netwolfuk
Copy link
Member

Thanks for the update. I didn't really think about it, but I guess it makes sense that the id is allocated when it starts. Otherwise there would be buildIds that are never used when multiple queued events are grouped into a single build.

I'll merge this branch into master and release a new alpha in the next few weeks.

@nrukavkov
Copy link
Author

@netwolfuk do you have plans to release v1.2?

@netwolfuk
Copy link
Member

Hi @nrukavkov. Yes. A new alpha will be released this weekend.

Alpha 7 adds project parameter editing in the UI. Alpha 8 is filter editing in the UI.

I suspect the final release is still a few months away. But the alphas are very stable.

@netwolfuk
Copy link
Member

@netwolfuk netwolfuk added available in alpha or beta release item is released in a "pre-release" version ready for testing. and removed available in alpha or beta release item is released in a "pre-release" version ready for testing. labels Sep 12, 2020
@netwolfuk
Copy link
Member

Sorry for the delay. We found bug #167 just before I wanted to release, and I thought it was going to affect all users.

Alpha 7 will be released this weekend.

@netwolfuk netwolfuk added the available in alpha or beta release item is released in a "pre-release" version ready for testing. label Sep 20, 2020
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. enhancement waiting for release
Projects
None yet
Development

No branches or pull requests

2 participants