Create Pipeline Webhooks

Pipeline Webhooks

In the previous chapter we learn about EventListeners, TriggerBindings, etc. also the role played by webhooks. Don’t forget that webhooks are generic but the way you create them and also potentially the payload of events are specific to the git provider.

In this guide you’re going to create the webhooks you need to trigger the CI and CD pipelines for both Events and Gateway microservices, namely:

  • Kitchensink CI Push: this webhook will send events only when changes are pushed to the source code repository

  • Kitchensink CD PullRequest: this webhook will send events only if a PullRequest is merged into the Gramola configuration repository

Create Git PAT

Before you can create the webhooks you need a Personal Access Token (PAT), which probably has been lost…​ no problem following this instruction to generate another one.

You can run this command as often as needed

GIT_PAT=$(curl -k -s -XPOST -H "Content-Type: application/json" \
  -d '{"name":"cicd'"${RANDOM}"'","scopes": ["repo"]}' \
  -u %USERNAME%:openshift \
  https://repository-gitea-system.apps.%BASE_SUBDOMAIN%/api/v1/users/%USERNAME%/tokens | jq -r .sha1)
echo "GIT_PAT=${GIT_PAT}"

Kitchensink CI Webhook

KITCHENSINK_CI_EL_LISTENER_HOST=$(oc get route/el-kitchensink-ci-pl-push-gitea-listener -n cicd-tekton-%USERNAME% -o jsonpath='{.status.ingress[0].host}')

curl -k -X 'POST' "https://repository-gitea-system.apps.%BASE_SUBDOMAIN%/api/v1/repos/%USERNAME%/kitchensink/hooks" \
  -H "accept: application/json" \
  -H "Authorization: token ${GIT_PAT}" \
  -H "Content-Type: application/json" \
  -d '{
  "active": true,
  "branch_filter": "*",
  "config": {
     "content_type": "json",
     "url": "http://'"${KITCHENSINK_CI_EL_LISTENER_HOST}"'"
  },
  "events": [
    "push" (1)
  ],
  "type": "gitea"
}'
1 Only push events

Expected output:

{"id":1,"type":"gitea","config":{"content_type":"json","url":""push","active":true,"updated_at":"2021-11-12T10:14:15Z","created_at":"2021-11-12T10:14:15Z"}

Kitchensink CD Webhook

KITCHENSINK_CD_EL_LISTENER_HOST=$(oc get route/el-kitchensink-cd-pl-pr-gitea-listener -n cicd-tekton-%USERNAME% -o jsonpath='{.status.ingress[0].host}')

curl -k -X 'POST' "https://repository-gitea-system.apps.%BASE_SUBDOMAIN%/api/v1/repos/%USERNAME%/kitchensink-conf/hooks" \
  -H "accept: application/json" \
  -H "Authorization: token ${GIT_PAT}" \
  -H "Content-Type: application/json" \
  -d '{
  "active": true,
  "branch_filter": "*",
  "config": {
     "content_type": "json",
     "url": "http://'"${KITCHENSINK_CD_EL_LISTENER_HOST}"'"
  },
  "events": [
    "pull_request" (1)
  ],
  "type": "gitea"
}'
1 Only pull_request events

Expected output:

{"id":2,"type":"gitea","config":{"content_type":"json","url":""pull_request","pull_request_assign","pull_request_label","pull_request_milestone","pull_request_comment","pull_request_review_approved","pull_request_review_rejected","pull_request_review_comment","pull_request_sync","active":true,"updated_at":"2021-11-12T10:16:31Z","created_at":"2021-11-12T10:16:31Z"}