[英]Jenkins - How to pass parameters from a downstream job to its parent upstream?
After cracking the reverse problem, I now need to pass some simple data back from each downstream job to its parent. 解决了反向问题之后,我现在需要将一些简单的数据从每个下游作业传递回其父作业。 One obvious option is to write the data to a file, save it as an artifact and then have the parent upstream job retrieve the artifacts of all its downstream jobs. 一个显而易见的选择是将数据写入文件,将其另存为工件,然后让父上游作业检索其所有下游作业的工件。
Any other idea? 还有其他想法吗? I have not seen any plugins for this and both the Build Pipeline and Workflow plugin seem to be overkill for this. 我还没有看到任何与此相关的插件,而Build Pipeline和Workflow插件似乎对此都显得过高了。
Thanks, Amir 谢谢,阿米尔
The solution that I chose does not use any Jenkins mechanism, since there are none... 我选择的解决方案不使用任何Jenkins机制,因为没有解决方案...
I ended up using RabbitMQ messaging queue, as follows: 我最终使用RabbitMQ消息传递队列,如下所示:
1. Set up a persistent RabbitMQ server on a separate host (which is not connected to Jenkins). 1.在单独的主机(未连接到Jenkins)上设置持久化RabbitMQ服务器。 Host is CentOS 7. 主机是CentOS 7。
2. Added a pub/sub subscriber in the upstream job. 2.在上游作业中添加了发布/ 订阅订户 。
3. Added a pub/sub publisher in the downstream job. 3.在下游作业中添加了发布/订阅发布者 。
The upstream subscriber polls the message queue for messages published by the downstream job and acts upon receiving those message. 上游订户轮询消息队列以查找下游作业发布的消息,并在接收到这些消息后采取行动。
This has the added benefit that downstream jobs can inter-communicate via the same mechanism. 这样做还有一个好处,就是下游作业可以通过相同的机制进行相互通信。
All scripts are in Python, so I am using pika to interact with RabbitMQ. 所有脚本均使用Python,因此我正在使用pika与RabbitMQ进行交互。
Pika: https://pika.readthedocs.org/en/latest/index.html 皮卡(Pika): https : //pika.readthedocs.org/en/latest/index.html
I am interesting in gathering more details about the context of such requirement... I am not convince by the effectiveness of job dependencies. 我对收集有关此类要求的上下文的更多细节很感兴趣……我对工作依赖性的有效性并不信服。 You should consider the following algorithm. 您应该考虑以下算法。
A (manual event) execute B (forced event), then execute C (forced event) A(手动事件)执行B(强制事件),然后执行C(强制事件)
and the other sequence (which shoulf match more with native Jenkins way of life) 以及其他序列(这应该与詹金斯人的生活方式更加匹配)
A (manual event ) update artefact a, B ( artefact change surveil on a) is executed and update artefact b, C (artefact change surveil on a -or b if sequence required) is executed and update artefact c, D (other job artefact change surveil on b and c (or c if sequence B,C is required) is executed and finished the work. 执行A(手动事件)更新工件a,B(a上的工件变化监视),并执行更新工件b,C(如果需要序列,则在-或b上进行工件变化监视)并更新工件c,D(其他作业工件)完成对b和c的监视(或c,如果需要顺序B,C),并完成工作。
Then you will focused on when does a job is started (triggering system - SCM event trigger, FStrigger, URLTrigger, IvyTrigger, ScriptTrigger) and what does a job is producing. 然后,您将关注作业何时开始(触发系统-SCM事件触发器,FStrigger,URLTrigger,IvyTrigger,ScriptTrigger)以及作业产生的内容。 (deployArtefact, promotedbuild, etc ...) (部署人工产品,promotedbuild等)
To manage variability you should also have a glance at Variable extractor plugin ( https://github.com/cittools/variables-extractor-plugin ) that implements a regular expression variable reader in the same syntax than Python named regexp wrapper.) Sometimes, it may be usefull. 为了管理可变性,您还应该浏览一下Variable extractor插件( https://github.com/cittools/variables-extractor-plugin ),该插件以与名为regexp wrapper的Python相同的语法实现正则表达式变量读取器。这可能是有用的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.