简体   繁体   English

使用Webhook和手册的Jenkins作业触发器

[英]Jenkins job trigger using webhook and manual

I have situation. 我有情况 I have configure single Jenkins job for more than 1 environment. 我已经为多个环境配置了单个Jenkins作业。 But development environment , job should start automatically using webhook and for other using manual. 但是开发环境下,作业应该使用webhook自动启动,而其他则应使用手动启动。 So, any 1 working fine for me. 所以,任何一个对我来说都很好。 Anyone know how to create such job? 有人知道如何创造这样的工作吗? Or is it advisable to use 2 different job ie for manual and for automatic? 还是建议使用2种不同的工作,即手动和自动?

You can achieve this scenario using two different approaches: 您可以使用两种不同的方法来实现此方案:

Free style / Maven Jobs: 自由风格/ Maven Jobs:

Jenkins Build Pipeline plugin. Jenkins Build Pipeline插件。

Build Pipeline link 建立管道链接

First we have to create a Jenkins job which will be triggered by web-hook. 首先,我们必须创建一个由Web-hook触发的Jenkins作业。 Then we need to create downstream jobs for each environment. 然后,我们需要为每个环境创建下游作业。 We can trigger those downstream jobs either automatically or manually based on condition. 我们可以根据条件自动或手动触发这些下游作业。

Pipeline Jobs: 管道作业:

You have add a step for manual interruption. 您已添加了一个手动中断步骤。 So that it will wait for your approval to execute next steps. 这样它将等待您的批准才能执行下一步。

Jenkins Input Step for approval Jenkins输入步骤以供批准

You can achieve your objective by creating a pipeline. 您可以通过创建管道来实现目标。 Create a job for your development environment and configure it using github webhook, other job you can mention it under builds other projects option in your development jobs configuration. 为您的开发环境创建一个作业,并使用github webhook对其进行配置,您可以在开发作业配置中的builds other projects选项下提及该作业。 This will create a pipeline of two jobs for you, and first one will get triggered automatically as required. 这将为您创建一个包含两个作业的管道,第一个作业将根据需要自动触发。 You can select on what instance you want second one to run under build other project. 您可以选择希望哪个实例在构建其他项目下运行。

Other way is to have your second project job as parameterized one, so it wont be triggerd unless you pass it some values (you will have to use trigger parameterized build option in your first jobs config). 另一种方法是将第二个项目作业设置为参数化,因此除非您传递一些值(除非您必须在第一个作业配置中使用触发器参数化的生成选项),否则它不会被触发。

Simplest way just create pipeline of two jobs as said, and disable the second one. 最简单的方法是按照所述创建两个作业的管道,然后禁用第二个作业。 You can trigger it manually by enabling it as u need. 您可以根据需要启用它来手动触发它。

I hope this will help you, feel free to contact in case of any queries. 希望对您有所帮助,如有任何疑问,请随时联系。

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

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