Automatically pin the current build
Hello,
I have a configuration where the last step in the configuration runs a script that executes REST API commands to pin the current build. In the script, I use %teamcity.serverUrl% and %system.teamcity.buildType.id% to get a list of all the builds in the configuration. Then I unpin all those builds. Then I utilize %teamcity.build.id% to pin the current build. I get an error because it seems the build doesn't exist (in the DB?) yet and therefore can't be pinned. Is there a proper way to do this or am I just doing something wrong? Thanks!
Please sign in to leave a comment.
Since there doesn't seem to be a built in way to do this, we've come up with a work around.
The goal is to automatically pin the current build every time the configuration is run. The issue is the build doesn't exist in the DB until the configuration has completed running. So when we try to do a REST API call to pin the current build as it is running, the DB returns saying the build ID doesn't exist.
This is how we got around it. First, we created a Python v3 script (let's call it kickoff.py) that uses the "requests" Python module to send an HTTP get request to TeamCity to add a build to the queue. As part of the HTTP URL, we pass 2 system variables, the ID and build type of the build we want to pin.
Here is the TeamCity documentation for building up the HTTP get URL.
http://confluence.jetbrains.com/display/TCD7/Accessing+Server+by+HTTP
Next, we create another Python v3 script (let's call it pin_build.py) that again uses the "requests" Python module to send TeamCity REST API requests to the TeamCity server. In this case, there are three unique requests: 1. get a list of all builds for a configuration, 2. Unpin all those builds, 3. pin the latest build in the configuration.
Here is the TeamCity documentation for the REST API.
http://confluence.jetbrains.com/display/TW/REST+API+Plugin
Now, to connect everything together. Here are all the parts:
We added a delay (5 second sleep call) in pin_build.py so we didn't run into race conditions between Configuration 1 and Configuration 2.
Hope this helps someone else out!
Hi,
I just opened this feature request: please vote for it if you find it useful:
https://youtrack.jetbrains.com/issue/TW-38017