从 TeamCity 向 Jenkins 上的 运行 自动化测试发送命令

Send command from TeamCity to run automation tests on Jenkins

有没有办法在 TeamCity 中添加构建步骤,向 Jenkins 服务器发送请求,运行 在 Jenkins 中添加一些自动化测试脚本并向 Teamcity 发回响应。

这个想法基本上是自动化整个部署过程,其中还包括 运行 使用 python 脚本创建的一些自动化测试(将在 Jenkins 上完成)。

我不确定这是否是最好的方法,但有没有更好的方法来实现这一点?还有关于如何从 Teamcity 向 Jenkins 发送命令的任何提示吗?

你可以像评论中提到的那样发起一个http请求来开始对Jenkins的测试。

至于将结果 bach 发布到 TeamCity,可能的解决方案可能是:

  • 在 Jenkins 上完成测试后,发布可以从外部(通过 TeamCity)访问并由 TeamCity 解释/报告的结果(在任何 supported formats), or manually, by the script, that will be run by TeamCity, using service messages
  • 创建将在 Jenkins 构建之后处理测试的构建配置
  • 设置一个URL build trigger插件,为创建的构建配置配置触发器。将触发器指向发布结果的地址。一旦发布的内容发生变化,构建就会开始,您将能够将测试结果下载到 TeamCity 并进行处理

第一部分有一个易于实施的解决方案,即从 Teamcity 向 Jenkins 发送命令

使用 CURL:

Install/copy Curl 到 Teamcity 代理。 然后在您的 TC 构建配置中,创建一个类似于下面的新命令行构建步骤(根据您的需要修改参数)

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%"

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

在这里,我什至可以使用“--数据”将内部版本号传递给 Jenkins

在 Jenkins 构建配置下执行以下操作:

  • 在 Jenkins 配置中:

在 Jenkins 配置中,更新以下值:

"This project is parameterized"

Name: Build_Number
Default Value: 1.2.0

"Trigger builds remotely"

  Authentication Token: rtbuild

可选:用于设置版本号

"Set Build Name"

  Build Name: #${Build_numuber}

完成,你很好 go.please 如果你有更多问题,请告诉我你。


以上是初始评论的实现

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.