2016-03-22 67 views
1

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

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

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

+0

你可以通过调用某些URL开始詹金斯作业,检查出https://wiki.jenkins-ci.org/display/JENKINS/参数化+构建部分“使用参数启动构建” –

回答

1

您可以发起一个http请求,正如在评论中提到的那样,可以在Jenkins上开始测试。

至于公布结果巴赫TeamCity的,可能的解决办法是:

  • 测试是在詹金斯完成后,公布由TeamCity的报道,可以(通过TeamCity的)外部访问和解释结果/ (在任何supported formats的),或者手动,由脚本,将由TeamCity的运行,使用service messages
  • 创建构建配置将处理试验后的詹金斯建立
  • 设置一个URL build trigger插件,配置触发器创建构建配置。将触发点指向发布结果的地址。发布的内容一旦更改,构建将开始,您将能够将测试结果下载到TeamCity并处理它们
0

为第一部分提供了一个易于实施的解决方案,即从TeamCity发送命令到詹金斯

使用curl:

安装/复制卷曲到TeamCity的代理。 ,然后在TC生成配置,创建类似下面的一个新的命令行构建的步骤(修改参数,以您的需求)

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

eg:curl --user admin:password -X POST http://jenkinssever:2123/job/test-build-image/buildWithParameters?token=rtbuild --data”Build_Number = 1.2。0"

这里我甚至可以使用通过版本号詹金斯‘ - 数据’

执行以下下詹金斯建筑结构:

  • 在詹金斯配置:

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

“此项目已参数化”

Name: Build_Number 
Default Value: 1.2.0 

“触发远程建立”

Authentication Token: rtbuild 

可选:设置集结号

“设置编译名称”

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.