The Direct Job Trigger feature is supported by Webhook to Jenkins version 6.1.0 and higher.
The Direct Job Trigger endpoint allows you to emulate the click of the Build Now button on the Jenkins job page for selected jobs. When the hook event is fired, it has the same effect as clicking this button manually for required jobs.
For example, you can configure the endpoint to build only develop or other baseline branches every time a pull request is merged or when running a staging deployment pipeline for newly pushed tags.
This article provides information regarding configuring Webhook to Jenkins using the Direct Job Trigger endpoint. See Bitbucket Configuration for additional configuration information.
This endpoint relies on basic Jenkins functionality and does not require additional plugins. The only required configuration steps are:
Configure the job to be built from a Bitbucket repository
Build the job with this repository at least once, so it can be found in Jenkins history and mapped to the Bitbucket repository.
Depending on the type of triggered job, it may have different behavior - as per job configuration. If this is a multibranch job, you can select one of the nested branches in a hook configuration.
To use the Direct Job Trigger endpoint, configure Jenkins credentials for the Webhook to Jenkins app, as you can trigger the job manually only when you are authenticated. See Setting up the Jenkins Instance page for instructions.
Configuring Jenkins instance(s)
Under the Post receive heading, select Enabled from the dropdown, or for a previously enabled Webhook to Jenkins configuration, click the Edit icon next to the dropdown.
Enter the URL for your Jenkins instance in the Jenkins URL field. Note that you need to configure this Jenkins instance to use the Direct Job Trigger feature.
Select Direct Job Trigger from the Jenkins Endpoint dropdown.
Type the name of the Jenkins job in Jobs List to see the list of matching jobs for this repository.
Select up to a maximum of five jobs to be triggered by Webhook to Jenkins.
To test your connection, go to the Jenkins instance(s), General settings, or Advanced Configuration tabs and click Test Configuration. When successful, a Connection Succeeded flag appears.
Click Save when finished.
Applying event filters limits events when the trigger fires, while the list of triggered jobs is fixed - those ones you have selected in the Jobs List field. Additionally, if the Branch Options exclusion filter is configured, matching jobs from selected ones are also excluded and will not be triggered.
If the Direct Job Trigger endpoint is configured for a project or repository, it is also used when you trigger build manually from Pull Request, Branches, or Source pages.
You can use additional hook settings together with Direct Job Notifier, including Job Parameters, which can be used to pass parameters to parametrized Jenkins jobs. This is useful to pass commit or branch names to generalized packaging or deployment jobs. See Sending URL Parameters to Jenkins for details.
You cannot test parametrized jobs from the hook configuration dialog with Test Configuration since it requires additional context for parameters not available at the moment of testing.