有没有办法在TeamCity中添加一个构建步骤,该步骤向Jenkins服务器发送请求,在Jenkins中运行一些自动化测试脚本并向Teamcity发回响应。
这个想法基本上是自动化整个部署过程,其中还包括运行使用python脚本创建的一些自动化测试(将在Jenkins上完成)。
我不确定这是否是最佳方式,但有没有更好的方法来实现这一目标?还有关于如何从Teamcity向Jenkins发送命令的任何提示?
答案 0 :(得分:1)
您可以发出http请求,如评论中所述,以便在Jenkins上开始测试。
至于将结果bach发布到TeamCity,可能的解决方案可能是:
答案 1 :(得分:1)
第一部分有一个易于实现的解决方案,即从Teamcity向Jenkins发送命令
使用CURL:
将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”
在这里,我甚至可以使用“ - data”
将内部版本号传递给Jenkins在Jenkins构建配置下执行以下操作:
在Jenkins配置中,更新以下值:
“此项目已参数化”
Name: Build_Number
Default Value: 1.2.0
“触发器远程构建”
Authentication Token: rtbuild
可选:用于设置内部版本号
“设置构建名称”
Build Name: #${Build_numuber}
完成了,你很高兴。如果你有更多问题,请告诉我。
以上是初始评论的实施
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.