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

我想要完成的是从 develop 分支签出代码,将其合并到 master 分支,构建 app.war,运行测试如果测试成功,则推送到 master 分支.

测试应该在需要 app.war 的单独作业中运行.

我目前的设置如下:

  1. Job Maindevelop 签出,合并到 master 并构建 app.war
  2. Job Main 在Post build step 中触发job Test (Test 需要app.war 以前构建的)
  3. 如果 Test 成功,Main 推送到 Post build action
  4. 中的 master 分支

我尝试使用 Copy Artifact Plugin,但问题是使用它时,我只能在触发 Test<时在 Post build action 中存档工件/code> 在构建后步骤.

如何将 app.war 传递给 Test 作业?是否可以使用 Copy Artifact Plugin?

解决方案

1.复制工件

您可以在其周围放置一个包装作业,并通过在其他项目上使用触发/调用构建,将构建作业和测试作业称为构建步骤.由于构建现在被封装在自己的作业中,您可以归档其工件并将它们复制到 Test 作业.

2.共享工作区

另一种方法是在构建和测试之间共享一个工作区.

3.将文件作为参数传递

将文件传递给下游作业的一种巧妙方法是,在

注意:您的下游作业确实不需要需要设置选项This build is parameterized,文件将被复制.这可能不再有效,请参阅评论.

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.

Tests should be run in separate job which needs app.war.

My current setup is as follows:

  1. Job Main checks out from develop, merges it to masterand builds app.war
  2. Job Main triggers job Test in Post build step (Test needs app.war previously built)
  3. If Test succeeds, Main pushes to master branch in Post build action

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.

How to pass app.war to Test job? Is it possible to do with Copy Artifact Plugin?

解决方案

1. Copying artifacts

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. Since the build is encapsuled in its own job now, you can archive its artifacts and copy them over to the Test job.

2. Share workspace

Another way would be to just share a workspace between build and test.

3. Pass file as parameter

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.

相关文章