Cloud customer?
Start for Free>
Upgrade in MyJFrog >
What's New in Cloud >







Overview

下面的例子展示了如何GitHub Action can be triggered using a custom webhook.

Page Contents

Step 1: Define the GitHub Workflow

Define a GitHub workflow as shown in the following example.

In the workflow YAML, theonclause must include theworkflow_dispatchevent 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:writepermission on the repo that holds the workflow.

Step 3: Define the Webhook

Define the webhook:

  • Using API, as shown below
    or
  • Using UI, as described in the sectionCustom Webhooks
  • 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.

  • No labels
Copyright © 2023 JFrog Ltd.