Teamcity get all docker images tags and set as parameter

Hello TeamCity community,

I'm trying to integrate TeamCity with a Docker registry via their respective APIs.

 The goal is:  
- Regularly fetch all available Docker image tags from a given repository  
- Dynamically populate a `select`-type parameter in TeamCity  
- So that when triggering a build, users can choose a tag from a dropdown list of valid image tags

Currently, I’m using a script to call the Docker Registry HTTP API (v2) and the TeamCity REST API to update the parameter.

It works in general, but there are some caveats:
- TeamCity doesn’t always preserve the `select` parameter type when updating via REST
- The REST API seems to ignore the `type=select` unless it’s defined manually in the UI first

Do you know a better or more stable way to implement this?
Maybe a recommended pattern using Snapshot Dependencies or Artifact Dependencies, or some DSL trick?

I’d love to hear if there’s a best practice for this scenario.

Thanks in advance!
 

0
1 comment

Hi! Updating existing select parameter values or creating a new select parameter with a set of values via the REST API is a viable solution. The same can also be achieved using Kotlin DSL, but the REST API should be equally reliable.

If you can consistently reproduce the issue where TeamCity does not preserve the select parameter type when updating via REST API, please share the steps to reproduce it.

For now, the issue of ignoring type=select could be due to a payload problem or incorrect request parameters. I tested it using curl (see the listing below), and it worked as expected.

BASE_URL="https://teamcity"
TOKEN="eyJ0eXAiOiAiVENWMiJ9...."
BUILD_TYPE_ID="MyBuildConfiguration"
PARAMETER_NAME="image"
curl -s "$BASE_URL/app/rest/buildTypes/id:$BUILD_TYPE_ID/parameters/$PARAMETER_NAME" \
  -X PUT \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d @payload.json

payload.json:

{
  "value": "",
  "type": {
    "rawValue": "select display='normal' data_1='image1' data_2='image2' data_3='image3' data_4='image4'"
  }
}
0

Please sign in to leave a comment.