Send command from TeamCity to run automation tests on Jenkins

霸气de小男生 提交于 2019-12-13 17:23:17

问题


Is there a way to add a build step in TeamCity which sends a request to Jenkins server, run some automation test scripts in Jenkins and sends back a response to Teamcity.

The idea basically is to automate the whole deployment process which also includes running of some automation tests created using python scripts (which will be done on Jenkins).

I am not sure if this is the best way of doing it but are there any better ways to achieve this? Also any hints on how to send command from Teamcity to Jenkins?


回答1:


You can make an http request, as mentioned in the comment to start tests on Jenkins.

As for publishing the results bach to TeamCity, the possible solution might be:

  • after tests are done on Jenkins, publish the results that can be accessed externally (by TeamCity) and interpreted / reported by TeamCity (either in any of the supported formats), or manually, by the script, that will be run by TeamCity, using service messages
  • create a build configuration that will process the tests after the Jenkins build
  • set up a URL build trigger plugin, configure the trigger for the created build configuration. Point the trigger to the address where results are published. As soon as the content published is changed, the build will start and you will be able to download the tests results to TeamCity and process them



回答2:


Got an easy to implement solution for the first part i.e. sending command from Teamcity to Jenkins

Using CURL:

Install/copy Curl to the Teamcity agent. and then in your TC build configurations, create a new Command line build step similar to below (modify the parameters to your needs)

curl --user %jenkins_user%:%jenkins_pwd% -X POST http://%jenkins_instance_withport%/job/%jenkins_jobs_name%/buildWithParameters?token=%jenkins_token% --data "Build_Number=%build.number%"

e.g: curl --user admin:password -X POST http://jenkinssever:2123/job/test-build-image/buildWithParameters?token=rtbuild --data "Build_Number=1.2.0"

Here i could even pass the build number to Jenkins by using "-- data"

Do the below under Jenkins build configuration:

  • In Jenkins configuration:

In Jenkins configuration, update the below values:

"This project is parameterized"

Name: Build_Number
Default Value: 1.2.0

"Trigger builds remotely"

  Authentication Token: rtbuild

Optional: for setting build number

"Set Build Name"

  Build Name: #${Build_numuber}

done and you are good to go.please do let me know you if you have more questions.


the above is the implementation of the Initial comment

I think I found a way while trying to solve similar use-case, did it for batch files in Teamcity build steps. for Jenkins, we have to modify accordingly.
Also is there any specific reason for using Teamcity and Jenkins simultaneously, unless you are making use of already created Jenkins build?

Steps:

Get CLI based command for Jenkins:
https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+CLI

you can achieve in two ways

Method 1:

 As build step is in current build.
Create a build step before your current step and trigger the Jenkins build using CLI 
Based on the return value of the Jenkins build step, next step will execute

Method 2:

 create a new build with above CLI step and add a dependency in your primary build.
so whenever the primary build is started, it will start the dependent CLI jenkins build. and once the dependent build is completed, will return success/failure, based on that the primary build will start.

i haven't tested the CLI of Jenkins but as Teamcity supports the steps and dependencies structure, expecting this will work.
will keep posted once i implement it.


来源:https://stackoverflow.com/questions/36157797/send-command-from-teamcity-to-run-automation-tests-on-jenkins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!