OutgoingWebhook

JFrog Pipelines Documentation

ft:sourceType
Paligo

An OutgoingWebhook resource uses HTTP to send information from a step to an external API endpoint through an Outgoing Webhook Integration.

When an OutgoingWebhook resource is specified as anoutputResourcefor a step and has an attached payload (including an empty payload), at the completion of the step's execution, the payload is sent to the endpoint specified in the Outgoing Webhook Integration. If required, this can be overridden by setting the resource's skipWebhook environment variable as true.

To attach the outgoing payload, use the set_payload utility function. If no payload is attached, no message is sent through the webhook.

YAML Schema
resources:
  - name:               <string>
    type:               OutgoingWebhook
    configuration:
      webhookName: <string>                           # name of an Outgoing Webhook Integration
      method: <GET|PUT|POST|DELETE|PATCH>             # default POST
      Parameters: <string>                            # query string to be appended to the outgoing URL
      path:       <string>
      headers:
        Content-type: <valid request content types> 
        accept: xyc
Tags
name

An alphanumeric string (underscores are permitted) that identifies the resource.

type

Must be OutgoingWebhook for this resource type.

configuration

Specifies all configuration selections for the resource.

Tag

Description

Required/Optional

webhookName

The name of an Outgoing Webhook Integration

Required

method

The HTTP method to use: GET | PUT | POST | DELETE | PATCH

The default is POST.

Optional

Parameters

A query string to be appended to the outgoing URL

Optional

path

Path for the outgoing URL

Optional

headers

Any HTTP entity headers to include. For example, content-type to specify any the type of content returned.

Optional

Environment Variables

Whenever Webhook is used in a step, a set of environment variables is automatically made available that you can use in your step.

Environment Variable

Description

                                       res_<resource_name>_name
                                    

Name of the resource

res_<resource_name>_payload

The JSON payload attached to the resource

res_<resource_name>_skipWebhook

When set to true, the outgoing webhook will not be sent. This is useful to inhibit sending of a prepared webhook in a step's onFailuresection.

Defaults to false.

Examples

The Pipelines DSL for this example is available in this repository in the JFrog GitHub account.

Example 1

Outgoing Form URL Webhook

resources:
  - name: My_OutHook_formurl_Resource
    type: OutgoingWebhook
    configuration:
      webhookName: My_OutgoingWebhookIntegration
      path: /url
      headers:
        content-type: application/x-www-form-urlencoded

pipelines:
  - name: ExamplePipeline
    steps:
      - name: my_send_hook_formurl
        type: Bash
        configuration:
          outputResources:
            - name: My_OutHook_formurl_Resource
        execution:
          onExecute:
            - echo "hello world"
            - formUrlEncodedPayload="foo=bar&runNumber=$run_number&stepName=$step_name"
            - set_payload My_OutHook_formurl_Resource "$formUrlEncodedPayload"

Example 2

Outgoing JSON Webhook

resources:
  - name:               MyOutgoingJSONResource
    type:               OutgoingWebhook
    configuration:
      webhookName: MyOutgoingJSONResource
      path: /json

pipelines:
  - name: ExamplePipeline
        steps:
    - name: my_send_hook_json
      type: Bash
      configuration:
        outputResources:
          - name: MyOutgoingJSONResource
      execution:
          onExecute:
            - jsonPayload="{\"runNumber\":\"$run_number\", \"stepName\":\"$step_name\"}"
            - set_payload MyOutgoingJSONResource "$jsonPayload"
          onFailure:
            - export res_MyOutgoingJSONResource_skipWebHook=true
          onSuccess:
            - echo "Payload sent by "$res_MyOutgoingJSONResource_name":"
            - echo $res_MyOutgoingJSONResource_payload