【问题标题】:Send command from TeamCity to run automation tests on Jenkins从 TeamCity 发送命令以在 Jenkins 上运行自动化测试
【发布时间】:2016-03-22 14:56:16
【问题描述】:

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

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

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

【问题讨论】:

标签: jenkins teamcity jenkins-plugins


【解决方案1】:

您可以发出 http 请求,如评论中所述,开始对 Jenkins 进行测试。

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

  • 在 Jenkins 上完成测试后,发布可以从外部访问(通过 TeamCity)并由 TeamCity 解释/报告的结果(在任何 supported formats 中),或者手动,通过脚本,将运行通过 TeamCity,使用 service messages
  • 创建将在 Jenkins 构建后处理测试的构建配置
  • 设置一个URL build trigger插件,为创建的构建配置配置触发器。将触发器指向发布结果的地址。一旦发布的内容发生更改,构建就会开始,您可以将测试结果下载到 TeamCity 并进行处理

【讨论】:

    【解决方案2】:

    第一部分有一个易于实施的解决方案,即从 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 配置中:

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

    “此项目已参数化”

    Name: Build_Number
    Default Value: 1.2.0
    

    “触发器远程构建”

      Authentication Token: rtbuild
    

    可选:用于设置内部版本号

    “设置构建名称”

      Build Name: #${Build_numuber}
    

    完成了,您可以开始了。如果您有更多问题,请告诉我。


    以上是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.
    

    【讨论】:

      猜你喜欢
      • 2012-07-19
      • 1970-01-01
      • 1970-01-01
      • 2011-01-03
      • 2015-05-08
      • 1970-01-01
      • 2014-01-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多