TeamCity: Disable build trigger for all TeamCity projects - teamcity

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.

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:
Get all build configurations
GET http://dummyhost.com/guestAuth/app/rest/buildTypes/
For each build configuration get all triggers
GET http://dummyhost.com/guestAuth/app/rest/buildTypes/id:***YOUR_BUILD_CONFIGID***/triggers/
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

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.

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

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"

Related

Trigger remote jenkins job with specific build id

I have pipeline that triggers multiple builds on remote jenkins job.
Problem is, when there are multiple builds triggered at same time, following command:
JENKINS_BUILD_ID=$(curl -k --silent --netrc-file "$HOME/.netrc" "${JENKINS_URL}/job/${JOB_NAME}/api/json" | grep -Po '"nextBuildNumber":\K\d+')
returns same build numbers( for example 125 is next build id).
In jenkins job configuration, I set up build name to be:
${ENV,var="WORKFLOW_NAME"}
But in api, to get logs, I need to use that build number(for example 125), is there way to use parameter in api (jenkins_job/WORKFLOW_NAME instead of default build number), where WORKFLOW_NAME is parameter parsed with remote trigger:
curl -k -X POST --netrc-file "$HOME/.netrc" "${JENKINS_URL}/job/{$JOB_NAME}/buildWithParameters" \
-F WORKFLOW_NAME="$WORKFLOW_NAME"

JIRA XRAY plugin creates duplicate test case when importing using API and feature file

I have a bash script that takes all the feature files from a specific directory and uses /rest/raven/1.0/import/feature?projectKey=XYZ XRAY-JIRA API to create TEST CASES in JIRA.
XRAY version 4.2.1_j7
I am running this script in a JENKINS-PIPELINE but the problem is when I run it for the first time it creates test cases which are correct but when I re-run the build it starts creating the same test cases again (duplicating them), any suggestion / reason why this is happening
My bash script:
#!/bin/bash
find <DIR_PATH> -type f -name "*.feature" | while read fname;
do
curl -H "Content-Type:multipart/form-data" -X $USERNAME:$PASSWORD -F "file=#$fname"
https://<JIRA_URL>/rest/raven/1.0/import/feature?projectKey=XYZ
done
Sample feature file:
Feature Facebook Login
#Login
Scenario: Log in to FB app
Given: User is at FB login page
When User enters username and password
Then User is logged in successfully
Please suggest me how and where can I debug to fix the issue
Thanks
First, I would highly recommend you to upgrade to the latest version is your current version is "rather old". Version 6.0 was just released few days ago.
I don't any open bug related to that, except this bug that been solved many releases ago.
You can try importing using a zip file, in a single request (which is more efficient btw). Maybe this approach implicitly addresses your problem, in the version in that you have.
Example:
rm -f features.zip
zip -r features.zip src/test/resources/calculator/ -i \*.feature
curl -H "Content-Type: multipart/form-data" -u admin:admin -F "file=#features.zip" "http://192.168.56.102/rest/raven/1.0/import/feature?projectKey=CALC"
If the problem persists, then mostly there's a bug there; please reach out Xray support team, so the team can properly analyze it with you.

Jenkins: how would i bash script the initialAdminPassword set up for a dockerfile as opposed to pasting into the browser

Is it possible to bash script the setup process of jenkins, for example i have jenkins container set-up on my local machine, i would like to complete jenkins set-up entirely on bash for the purpose of scripting this entirely from a dockerfile.
I need to be able to pass initialAdminPassword without the use of a browser and just from the terminal.
Is it possible to complete the set-up from the terminal?
Yes it is possible to skip the manual setup.
I don't know your particular setup, but let's assume you retrieve the password from jenkins instance :
cat /var/jenkins_home/secrets/initialAdminPassword
or
docker exec "myjenkinscontainer" bash -c 'cat $JENKINS_HOME/secrets/initialAdminPassword'
You could then connect to Jenkins as admin, using that password.
curl --silent -u "admin:$mypassword" http://localhost:8080/manage
If you've configured Jenkins Security to not allow API calls, then you might require to generate first a crumb token that you would use in every request, instead of the password. To issue a crumb token, you might do something similar :
curl -s 'http://admin:$mypassword#localhost:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)'
Then you might need pass this crumb value instead of password in further requests.
Depending on your situation / Jenkins configuration, I might provide more details.

How to upload .jtl file to blazemeter sense

I created a Jenkins job where it run some JMeter scripts and return .jtl files. Now, I want to upload this files to Blazemeter Sense to see the performance test, downloads pdf reports, etc.
I've searched a lot of information, where I find that to upload some file, I can use this command thats running from Windows CMD:
curl -v https://sense.blazemeter.com/api/files -H "Authorization: Token 'cat ~/.loadosophia.token'" -F "projectKey=Project_name" -F "jtl_file=#jtl.gz"
REFERENCE: https://sense.blazemeter.com/wiki/help:uploads/
The only values that I change are
cat ~/.loadosophia.token, where I replaced for my Upload Token (finded in Blazemeter Sense -> Options -> Settings -> Your Upload Token)
projectKey where I replaced by my project name (test_taurus)
jtl_file where I replaced by the file directory generated by Jmeter test (.jtl)
The final command is:
curl -v https://sense.blazemeter.com/api/files -H "Authorization: Token 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXYLaa'" -F "projectKey=test_taurus" -F "jtl_file=/path/of/file/file.jtl"
I missed some? What is my wrong? Existe another posibility to make it?
Thanks everyone
U P D A T E:
I did what Dmitri T said. Thats works. But when I run the command, the output is the following:
What could be the issue?
You need to remove quotation marks around the token
You need to add an "at" symbol before the .jtl file path
Fixed command would be something like:
curl -v https://sense.blazemeter.com/api/files -H "Authorization: Token XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXYLaa" -F "projectKey=test_taurus" -F "jtl_file=#/path/of/file/file.jtl"
More information: Upload files with CURL
You might find BM.Sense Uploader plugin more convenient to use, the plugin can be installed using JMeter Plugins Manager:

Run XCode Integration from command line

I have set up os x server and bot which do build/test process. I need run this bot from command line.
Is it possible to run integration (CI on os x server) from command line?
It's quite late response, nevertheless hope it would help.
As you might know Xcode Server exposes WEB API.
So in order to launch integration just issue this command replacing YOUR_BOT_NAME part with actual bot name.
curl -sk -X POST -d '{ shouldClean: false }' https://localhost:20343/api/bots/`curl -sk https://localhost:20343/api/bots | jq '.results[] | select(.name == "YOUR_BOT_NAME") | ._id' | tr -d '"'`/integrations
Note this command utilises JQ command line JSON processor which is available via Homebrew:
brew install jq
Build can be done with xcodebuild. For tests, I don't know.

Resources