Create Worker

JFrog REST APIs

Content Type
REST API
ft:sourceType
Paligo

Description: Creates a worker service.

Since: 7.63.2

Security: Platform Admin, Project Admin (for Project Admin, the projectKey query parameter must be set and match the one in the Worker request body).

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

You use the same API to create all the workers. You differentiate between the type of worker created using the action parameter. Choose from the list of worker actions with which the worker is associated. Find the list of actions here.

filterCriteria

object

Mandatory for event-driven, artifact-related, and scheduled workers if enabled is set as true

This parameter defines the repositories to be used or excluded for most workers.

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
   }
}

For scheduled workers, this parameter defines the schedule details:

filterCriteria: { 
    schedule: {
        cron: string, // Cron expression to schedule the worker
        timezone: undefined | string // If provided, schedule is applied in the selected timezone
    }
}

artifactFilterCriteria.repoKeys

string[]

Mandatory for event-driven and artifact-related workers if filterCriteria is enabled

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.

projectKey

string

No

If set, this Worker will be available in the scope of the given project (editable by platform admin and project admin). If not set, this Worker will be global and only editable by platform admin.

If set, only actions that are compatible with projects are returned. If a project admin token is used, this query parameter is required and the user must have the role project admin for the project, otherwise an HTTP error 403 is returned. Once set, the projectKey cannot be changed.

schedule.cron

string

mandatory for scheduled workersCreate a Scheduled Worker

The cron expression that sets the schedule of worker execution. For example, 0 2 * * * executes the worker every day at 02:00 AM. The minimum recurrent time for worker execution is 1 minute.

schedule.timezone

string

No

The timezone in which the worker is scheduled to run. The default is the timezone set for the server.

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[],
    "shared": boolean,
    "debug": boolean,
    "projectKey": undefined | string
}

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 Type

{
    "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.