如何将文件传递给阻止上游作业的下游作业?
我想要完成的是从 develop
分支签出代码,将其合并到 master
分支,构建 app.war
,运行测试如果测试成功,则推送到 master
分支.
测试应该在需要 app.war
的单独作业中运行.
我目前的设置如下:
- Job
Main
从develop
签出,合并到master
并构建app.war
- Job
Main
在Post build step 中触发jobTest
(Test
需要app.war
以前构建的) - 如果
Test
成功,Main
推送到 Post build action 中的
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:
- Job
Main
checks out fromdevelop
, merges it tomaster
and buildsapp.war
- Job
Main
triggers jobTest
in Post build step (Test
needsapp.war
previously built) - If
Test
succeeds,Main
pushes tomaster
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.
相关文章