Build is not prioritized despite using queueAtTop=true in TeamCity's REST API

Hello,

I am using the TeamCity REST API to trigger builds, and I have set the queueAtTop=true parameter to prioritize the build. However, despite this, my build is still being placed at the bottom of the queue rather than at the top.

Here’s a snippet of the request body:

{  "branchName": "main",  "buildType": {"id": "%build_id%"},  "queueAtTop": "true" } 

TeamCity Professional 2024.07.3 (build 160765)

Has anyone experienced a similar issue? Could there be other factors affecting the build queue that I am overlooking? Any guidance or suggestions would be appreciated.

Thank you!

0
4 comments
Hi,

To help reproduce the issue, could you please share the API endpoint and the full request body?
Feel free to remove any sensitive information from both the endpoint and the request body
0

Hey Tom,

Thank you for the reply. Sure, I can share the whole code. I’ve actually created a meta-runner to run a custom build via the API as a build step. Here’s the full listing:

<meta-runner name="Run other build">
 <description>Run build via api</description>
 <settings>
   <parameters>
     <param name="env.ACCESS_TOKEN" value="******" spec="password display='hidden'" />
     <param name="env.BRANCH_NAME" value="" />
     <param name="env.BUILD_TRIGGERED_BY" value="%teamcity.build.triggeredBy.username%" spec="text display='hidden' readOnly='true'" />
     <param name="env.BUILD_TYPE_ID" value="" />
     <param name="env.PRIORITIZE_BUILD" value="false" spec="select data_1='false' data_2='true' display='normal'" />
     <param name="env.BUILD_URL" value="https://ci.babaluba.tech/viewLog.html?buildId=%teamcity.build.id%" spec="text display='hidden' readOnly='true'" />
     <param name="env.DOCKER_BUILDKIT" value="1" spec="text display='hidden' validationMode='any'" />
     <param name="env.TEAMCITY_SERVER_URL" value="%teamcity.serverUrl%" spec="text display='hidden' validationMode='any'" />
   </parameters>
   <build-runners>
     <runner name="Run build script" type="simpleRunner">
       <parameters>
         <param name="script.content"><![CDATA[#!/bin/bash
set -e
# Check if required environment variables are set
if [ -z "$TEAMCITY_SERVER_URL" ]; then
   echo "Error: TEAMCITY_SERVER_URL is not set"
   exit 1
fi
if [ -z "$BUILD_TYPE_ID" ]; then
   echo "Error: BUILD_TYPE_ID is not set"
   exit 1
fi
if [ -z "$BRANCH_NAME" ]; then
   echo "Error: BRANCH_NAME is not set"
   exit 1
fi
if [ -z "$ACCESS_TOKEN" ]; then
   echo "Error: ACCESS_TOKEN is not set"
   exit 1
fi
if [ "$PRIORITIZE_BUILD" == "true" ]; then
   QUEUE_AT_TOP="true"
else
   QUEUE_AT_TOP="false"
fi
REQUEST_BODY=$(cat <<EOF
{
   "branchName": "$BRANCH_NAME",
   "buildType": {"id": "$BUILD_TYPE_ID"},
   "queueAtTop": "$QUEUE_AT_TOP"
}
EOF
)
# Print the request body
echo "Request Body: $REQUEST_BODY"
# Trigger the build
RESPONSE=$(curl --trace-ascii -X POST \
   -H "Content-Type: application/json" \
   -H "Authorization: Bearer $ACCESS_TOKEN" \
   -d "$REQUEST_BODY" \
   "${TEAMCITY_SERVER_URL}/app/rest/buildQueue")
# Check if the build was triggered successfully
if echo "$RESPONSE" | grep -q "id=\""; then
   BUILD_ID=$(echo "$RESPONSE" | sed -n 's/.*id="\([^"]*\)".*/\1/p')
   echo "Build triggered successfully. Build ID: $BUILD_ID"
else
   echo "Failed to trigger build. Server response:"
   echo "$RESPONSE"
   exit 1
fi]]></param>
         <param name="teamcity.step.mode" value="default" />
         <param name="use.custom.script" value="true" />
       </parameters>
     </runner>
   </build-runners>
 </settings>
</meta-runner>

 

0

Hi, 

According to the addBuildToQueue documentation, the request body should contain a Build object.

Within the Build object, the triggeringOptions field is supported as documented here.

Therefore, please use the following request body:

{
  "buildType": {
    "id": "%build_id%"
  },
  "branchName": "main",
  "triggeringOptions": {
    "queueAtTop": true
  }
}
0

That helps, thanks a lot!

0

Please sign in to leave a comment.