The following example shows how a GitHub Action can be triggered using a custom webhook.
Step 1: Define the GitHub Workflow
Define a GitHub workflow as shown in the following example.
In the workflow YAML, the on
clause must include the workflow_dispatch
event so that Artifactory can trigger the workflow through GitHub REST API.
name: artifact_deployed on: # workflow_dispatch is mandatory, so that Artifactory can trigger # the workflow through GitHub REST API. workflow_dispatch: # inputs are optional, they may be used to convey contextual data # from the JFrog event to the workflow. inputs: artifact_path: required: true type: string jobs: build: runs-on: ubuntu-latest steps: - name: Print artifact_path run: echo The path is ${{ inputs.artifact_path }}
Step 2: Generate a Token
The generated token can be a Personal Access token. This token must allow the triggering of actions on the target GitHub repository.
The token must have theactions:write
permission on the repo that holds the workflow.
Step 3: Define the Webhook
Define the webhook using API, as shown below or using the UI.
Note
In the URL, provide the GitHub owner and repository
In the secrets, provide the token
POST /event/api/v1/subscriptions { "key": "trigger_action", "enabled": true, "event_filter": { "domain": "artifact", "event_types": [ "deployed" ], "criteria": { "anyLocal": true } }, "handlers": [ { "handler_type": "custom-webhook", "url": "https://api.github.com/repos/your/repo/actions/workflows/artifact_deployed.yml/dispatches", "payload": "{ \"ref\": \"main\" , \"inputs\": { \"artifact_path\": \"{{.data.repo_key}}/{{.data.path}}\" } }", "secrets": [ { "name": "token", "value": "***" } ], "http_headers": [ { "name": "Authorization", "value": "Bearer {{.secrets.token}}" }, { "name": "Accept", "value": "application/vnd.github+json" }, { "name": "Content-Type", "value": "application/json" } ] } ] }
Step 4: Deploy to Trigger
Deploy an artifact in any local Artifactory repository and the action will be triggered on the GitHub repository.