Jenkins管道:如何在不使用额外的代理/执行器的情况下触发另一个作业并等待它 [英] Jenkins pipeline: how to trigger another job and wait for it without using an extra agent/executor

查看:483
本文介绍了Jenkins管道:如何在不使用额外的代理/执行器的情况下触发另一个作业并等待它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置各种Jenkins管道,其最后阶段始终是运行一些验收测试.长话短说,所有产品的验收测试和测试数据(其中很多都是共享的)被检入同一存储库中,该存储库的大小约为0.5 GB.因此,似乎最好有一个单独的工作来进行验收测试,并通过每个管道的构建"步骤触发它,并使用适当的参数来运行相关测试. (有时在不重建产品的情况下重新运行这些测试也很有用)

I am trying to setup various Jenkins pipelines whose last stage is always to run some acceptance tests. To cut a long story short, acceptance tests and test data (much of which is shared) for all products are checked into the same repository which is about 0.5 GB in size. It therefore seemed best to have a separate job for the acceptance tests and trigger it with a "build" step from each pipeline with the appropriate arguments to run the relevant tests. (It is also sometimes useful to rerun these tests without rebuilding the product)

stage('AcceptanceTest') {
    steps {
        build job: 'run-tests', parameters: ..., wait: true
    }
}

到目前为止,我已经知道我可以:

So far I have seen that I can either:

  1. 正常触发该作业.但这使用了额外的代理/执行器, 似乎没有办法告诉它重复使用 构建(主管道).这两个管道均以"agent {label'master'}"开头,但是 似乎意味着在与主服务器匹配的节点上分配新代理".
  2. 使用"wait:false"参数触发作业.这不是 阻止执行程序,但这确实意味着我无法报告执行结果 在主管道中进行测试.它给人的印象是测试 阶段总是成功的.
  1. trigger the job as normal. But this uses an extra agent/executor, there doesn't seem to be a way to tell it to reuse the one from the build (main pipeline). Both pipelines start with "agent { label 'master' }" but that seems to mean "allocate a new agent on a node matching master".
  2. trigger the job with the "wait: false" argument. This doesn't block an executor but it does mean I can't report the results of the tests in the main pipeline. It gives the impression that the test stage has always succeeded.

有更好的方法吗?

推荐答案

我似乎已经解决了这一问题,方法是在主管道顶部添加"agent none",然后将"agent {label'master'}"移到建立阶段.然后,我可以在没有代理的情况下离开"AcceptanceTest"阶段,并像以前一样在运行测试"作业中对其进行定义.我从文档中得到的印象是,如果您将代理放在各个阶段,则所有阶段都必须有一个,但是事实并非如此.对于这个用例,这是幸运的...

I seem to have solved this, by adding "agent none" at the top of my main pipeline and moving "agent { label 'master' }" into the build stage. I can then leave my 'AcceptanceTest' stage without an agent and define it in the 'run-tests' job as before. I was under the impression from the docs that if you put agents in stages then all stages needed to have one, but it seems not to be the case. Which is lucky for this usecase...

这篇关于Jenkins管道:如何在不使用额外的代理/执行器的情况下触发另一个作业并等待它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆