Trigger a Pipeline by Using a Webhook
If you create a Jenkinsfile-based pipeline from a remote code repository, you can configure a webhook in the remote repository so that the pipeline is automatically triggered when changes are made to the remote repository.
This tutorial demonstrates how to trigger a pipeline by using a webhook.
Prerequisites
-
You need to enable the KubeSphere DevOps system.
-
You need to create a workspace, a DevOps project, and a user (
project-regular
). This account needs to be invited to the DevOps project and assigned theoperator
role. See Create Workspaces, Projects, Users and Roles if they are not ready. -
You need to create a Jenkinsfile-based pipeline from a remote code repository. For more information, see Create a Pipeline Using a Jenkinsfile.
Configure a Webhook
Get a webhook URL
-
Log in to the KubeSphere web console as
project-regular
. Go to your DevOps project and click a pipeline (for example,jenkins-in-scm
) to go to its details page. -
Click More and select Edit Settings in the drop-down list.
-
In the displayed dialog box, scroll down to Webhook to obtain the webhook push URL.
Set a webhook in the GitHub repository
-
Log in to GitHub and go to your own repository
devops-maven-sample
. -
Click Settings, click Webhooks, and click Add webhook.
-
Enter the webhook push URL of the pipeline for Payload URL and click Add webhook. This tutorial selects Just the push event for demonstration purposes. You can make other settings based on your needs. For more information, see the GitHub document.
-
The configured webhook is displayed on the Webhooks page.
Trigger the Pipeline by Using the Webhook
Submit a pull request to the repository
-
On the Code page of your own repository, click master and then select the sonarqube branch.
-
Go to
/deploy/dev-ol/
and click the filedevops-sample.yaml
. -
Click to edit the file. For example, change the value of
spec.replicas
to3
. -
Click Commit changes at the bottom of the page.
Check the webhook deliveries
-
On the Webhooks page of your own repository, click the webhook.
-
Click Recent Deliveries and click a specific delivery record to view its details.
Check the pipeline
-
Log in to the KubeSphere web console as
project-regular
. Go to your DevOps project and click the pipeline. -
On the Run Records tab, check that a new run is triggered by the pull request submitted to the
sonarqube
branch of the remote repository. -
Go to the Pods page of the project
kubesphere-sample-dev
and check the status of the 3 Pods. If the status of the 3 Pods is running, the pipeline is running properly.
Feedback
Was this page Helpful?
Receive the latest news, articles and updates from KubeSphere
Thanks for the feedback. If you have a specific question about how to use KubeSphere, ask it on Slack. Open an issue in the GitHub repo if you want to report a problem or suggest an improvement.