简体   繁体   English

如何将文件传递给阻止上游作业的下游作业?

[英]How to pass file to downstream job which blocks upstream job?

What I want to accomplish is to checkout code from develop branch, merge it to master branch, build app.war , run tests and if tests succeed push to master branch. 我想要完成的是从develop分支检出代码,将其合并到master分支,构建app.war ,运行测试以及如果测试成功推送到master分支。

Tests should be run in separate job which needs app.war . 测试应该在需要app.war单独工作中运行。

My current setup is as follows: 我目前的设置如下:

  1. Job Main checks out from develop , merges it to master and builds app.war Job Maindevelop检出,将其合并到master并构建app.war
  2. Job Main triggers job Test in Post build step ( Test needs app.war previously built) 作业Main后期构建步骤中触发作业TestTest需要先前构建的app.war
  3. If Test succeeds, Main pushes to master branch in Post build action 如果Test成功, Main将推送到Post构建操作中的 master分支

I tried to use Copy Artifact Plugin but the problem is that with it, I can only archive artifact in Post build action while I am triggering Test in Post build step . 我尝试使用复制工件插件,但问题是,使用它,我只能在Post构建操作中存档工件,而我在Post构建步骤中触发Test

How to pass app.war to Test job? 如何将app.war传递给Test作业? Is it possible to do with Copy Artifact Plugin ? 是否可以使用Copy Artifact Plugin

1. Copying artifacts 1.复制工件

You can put a wrapper job around it and have the Build job and the Test job called as build step by using Trigger/call builds on other projects . 您可以在其周围放置一个包装器作业,并通过在其他项目上使用Trigger / call构建将Build作业和Test作业调用为构建步骤。 Since the build is encapsuled in its own job now, you can archive its artifacts and copy them over to the Test job. 由于构建现在已封装在自己的作业中,因此您可以归档其工件并将其复制到Test作业。

2. Share workspace 2.共享工作区

Another way would be to just share a workspace between build and test. 另一种方法是在构建和测试之间共享工作空间。

3. Pass file as parameter 3.将文件作为参数传递

A neat way to pass a file to a downstream job is, to pass it as parameter with the help of the Parameterized Trigger Plugin . 将文件传递给下游作业的一种巧妙方法是,在参数化触发器插件的帮助下将其作为参数传递。

You push a file into your downstream job's workspace simply by selecting the parameter factory For every matching file, invoke one build in a build step Trigger/call builds on other projects . 只需选择参数工厂即可将文件推入下游作业的工作区。 对于每个匹配的文件,在构建步骤中调用一个构建其他项目上触发/调用构建 There you specify the target file (wildcards allowed) and the name it should get in the child workspace. 在那里,您指定目标文件(允许使用通配符)以及它应在子工作空间中获得的名称。

在此输入图像描述

Note: Your downstream job does not need to have the option This build is parameterized set, the file will be copied either way. 注意: 您的工作下游不需要可以选择此版本的参数设置,该文件将被复制两种方式。 Edit: This might not work anymore, see comments. 编辑:这可能不再起作用,请参阅注释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM