IAMbeginner
IAMbeginner

Reputation: 269

TeamCity: Disable build trigger for all TeamCity projects

I would like to ask is there any way to disable build triggers for all TeamCity projects by running a script?

I have a scenario that I need to disable all the build triggers to prevent the builds from running. This is because sometimes, I might need to perform some upgrading process on build agent machines which will take more than one day.

I do not wish to manually click on Disable buttons for every build triggers on every different TeamCity projects. Is there a way to automate this process?

Thanks in advance.

Upvotes: 7

Views: 6347

Answers (5)

Lobshunter
Lobshunter

Reputation: 89

At least since TeamCity 2021.2.3 (build 99711, the version that I use), build triggers can be disabled with one click.

enter image description here

Upvotes: -1

Vadzim
Vadzim

Reputation: 26160

Here is a bash script to bulk pause all (still not paused) build configurations by project name pattern via TeamCity REST API:

TEAMCITY_HOST=http://teamcity.company.com
CREDS="-u domain\user:password"
curl $CREDS --request GET "$TEAMCITY_HOST/app/rest/buildTypes/" \
| sed -r "s/(<buildType)/\n\\1/g" | grep "Project Name Regex" \
| grep -v 'paused="true"' | grep -Po '(?<=buildType id=")[^"]*' \
| xargs -I {} curl -v $CREDS --request PUT "$TEAMCITY_HOST/app/rest/buildTypes/id:{}/paused" --header "Content-Type: text/plain" --data "true"

Upvotes: 0

Didier Aupest
Didier Aupest

Reputation: 3367

Another solution might be to simply disable the agent, so no more builds will run.

Upvotes: 0

Oleksandr Kobylianskyi
Oleksandr Kobylianskyi

Reputation: 3370

Use Team City REST API.

Given your Team City is deployed at http://dummyhost.com and you enabled guest access with system admin role (otherwise just switch from guestAuth to httpAuth in URL and specify user with password in request, details are in documentation) you can do next:

  1. Get all build configurations GET http://dummyhost.com/guestAuth/app/rest/buildTypes/
  2. For each build configuration get all triggers GET http://dummyhost.com/guestAuth/app/rest/buildTypes/id:***YOUR_BUILD_CONFIGID***/triggers/
  3. For each trigger disable it PUT http://dummyhost.com/guestAuth/app/rest/buildTypes/id:***YOUR_BUILD_CONFIGID***/triggers/***YOUR_TRIGGER_ID***/disabled

See full documentation here

Upvotes: 6

sferencik
sferencik

Reputation: 3249

You can pause the build queue. See this video. This way you needn't touch the build configurations at all; you're just bringing the TC to a halt.

For agent-specific upgrades, it's best to disable only the agent you're working on. See here.

Neither of these is "by running a script" as you asked, but I take it you were only asking for a scripted solution to avoid a lot of GUI clicking.

Upvotes: 4

Related Questions