Create Worker

JFrog REST APIs

Content Type
REST API
ft:sourceType
Paligo

Description: Creates a worker service.

Since: 7.63.2

Security: Platform Admin

Usage: POST /worker/api/v1/workers

Produces: no-data

Header parameter: Authorization: Bearer

HTTP Request Payload Parameters

Parameter

Datatype

Mandatory

Description

key

string

Yes

The unique ID of the worker.

description

string

No

Description of the worker.

enabled

boolean

Yes

Whether to enable the worker immediately after creation.

The default values is true.

You can also set the value as false and enable the worker afterwards.

sourceCode

string

Yes

The worker script in TypeScript or JavaScript.

action

enum string

Yes

Choose one of the following worker actions with which the worker is associated.

  • BEFORE_DOWNLOAD

  • AFTER_DOWNLOAD

  • AFTER_SCAN

  • BEFORE_UPLOAD

  • AFTER_CREATE

  • AFTER_BUILD_INFO_SAVE

  • AFTER_MOVE

  • GENERIC_EVENT

  • BEFORE_CREATE_TOKEN

  • BEFORE_PROPERTY_CREATE

filterCriteria

object

Mandatory if enabled is set as true

Defines the repositories to be used or excluded.

filterCriteria: { 
    artifactFilterCriteria: {
        excludePatterns: undefined | string[], 
       // If provided, the worker is triggered only if the artifact path does NOT match any of the given patterns
        includePatterns: undefined | string[], 
       // If provided, the worker is triggered only if the artifact path matches one of the given patterns
        repoKeys: string[], 
       // The list of repositories that are allowed to trigger this worker
   }
}

artifactFilterCriteria.repoKeys

string[]

Mandatory if filterCriteria is mandatory

Defines which repositories are used when an action event occurs to trigger the worker.

You must provide at least one repository.

artifactFilterCriteria: {
       repoKeys: string[], 
       // The list of repositories that are allowed to trigger this worker
}

artifactFilterCriteria.includePatterns

string[]

No

Define patterns to match all repository paths for repositories identified in the repoKeys. Defines those repositories that trigger the worker.

artifactFilterCriteria: {
        includePatterns: undefined | string[], 
        // If provided, the worker is triggered only if the artifact path matches one of the given patterns
}

artifactFilterCriteria.excludePatterns

object

No

Define patterns to for all repository paths for repositories to be excluded in the repoKeys. Defines those repositories that do not trigger the worker.

artifactFilterCriteria: {
        excludePatterns: undefined | string[], 
        // If provided, the worker is triggered only if the artifact path does NOT match any of the given patterns
}

secrets

object

No

The secrets to be added to the worker.

You must provide the secret in the following format.

{
    "key": string,
    "value": string
}

shared

boolean

No

If TRUE, the Worker can be run by non-admin users. This is only relevant for Workers of type GENERIC_EVENT.

debug

boolean

No

If TRUE, status information and run history will be saved whether or not the Worker runs successfully.

Sample Usage

curl -X POST 'https://myserver.com/worker/api/v1/workers'
Ok

Sample Request

{
    "key": string,
    "description": string,
    "enabled": boolean,
    "sourceCode": string,
    "action": string,
    "filterCriteria": {
        "artifactFilterCriteria": {
            "includePatterns": undefined | string[],
            "excludePatterns": undefined | string[],
            "repoKeys": string[]
        }
    },
    "secrets": undefined | Secret[],
    "enabled": boolean,
    "sourceCode": string,
    "action": string,
    "shared": boolean,
    "debug": boolean,
}

Sample Response

{
  "logs": string, // All logs generated by the worker's script appear in one line.
  "beforeDownload": { // The type of action.
        "status": DownloadStatus, // The status returned by the worker script itself.
        "message": string, // The message returned by the worker script.
        "executionStatus": “STATUS_SUCCESS” // Execution status for the worker service.
    }
}

Secret Usage

{
    "key": string, // The name of the secret.
    "value": string // The value of the secret.
}

Action Usage

{
   enum Action {
    BEFORE_DOWNLOAD,
    AFTER_DOWNLOAD,
    BEFORE_UPLOAD,
    AFTER_CREATE
}

Success Response Codes:

201: OK response.

Error Response Codes:

400 The request payload is malformed.

401 Invalid credentials.

403 Insufficient permissions.

409 Conflict with workerKey.