CLI for JFrog Platform Services

This page describes how to use JFrog CLI with JFrog Platform Services. For more information on the CLI in general, see JFrog CLI.

Managing JFrog Workers

Workers is a JFrog Platform service that you can use to extend and control your execution flows. It provides a serverless execution environment. You can create workers to enhance the platform's functionality. Workers are triggered automatically by events within the JFrog Platform, which addresses specific use cases. For on-demand tasks, configure HTTP-triggered workers.

For more information about JFrog Workers.


Initialize JFrog Worker

This command is used to initialize a new JFrog worker.

ParameterCommand / Description
Command nameworker init
Abbreviationworker i
Command options:
--server-id[Optional] Server ID configured using the config command.
--timeout-ms[Default: 5000] The request timeout in milliseconds.
--force[Default: false] Whether to overwrite existing files.
--no-test[Default: false] Whether to skip test generation.
--application[Optional] The application that provides the event. If omitted the service will try to guess it and raise an error if no application is found.
--project-key[Optional] The key of the project that the worker should belong to.
Command arguments:
actionThe name of the action to init (eg: BEFORE_DOWNLOAD). To have the list of all available actions use jf worker list-event.
worker-nameThe name of the worker.

This command generates the following files:

  • manifest.json: Contains the Worker specification, including its name, code location, secrets, and other data useful to the Worker.
  • package.json: Describes the development dependencies of the Worker. This file is not used when executing your Worker in the runtime.
  • worker.ts: The Worker source code, populated with sample code for the event.
  • worker.spec.ts: The source code for the Worker's unit tests.
  • tsconfig.json: The TypeScript configuration file.
  • types.ts: A file containing the event's specific types that can be used in the Worker code.

Example: Initialize a BEFORE_DOWNLOAD Worker

This example initializes a new BEFORE_DOWNLOAD Worker named my-worker.

jf worker init BEFORE_DOWNLOAD my-worker

Test-Run JFrog Worker

Use this command to test-run a Worker. You must initialize the Worker before running this command. The command executes the Worker with its local content, so you can use it to test the Worker's execution before pushing local changes to the server.

ParameterCommand / Description
Command nameworker test-run
Abbreviationworker dry-run, worker dr, worker tr
Command options:
--server-id[Optional] Server ID configured using the config command.
--format[Default: json] Output format. Supported values: json, table. Available from JFrog CLI 2.105.0.
--timeout-ms[Default: 5000] The request timeout in milliseconds.
--no-secrets[Default: false] Do not use registered secrets.
Command arguments:
json-payloadThe json payload expected by the worker. Use - to read the payload from standard input. Use @<file-path> to read from a file located at .

Test-Run JFrog Worker Example

This example test-runs a Worker that has been initialized in the current directory, using a payload from a file named payload.json in the same directory.

jf worker dry-run @payload.json

--format json output (default)

{
  "key": "my-worker",
  "workerKey": "my-worker",
  "triggeredByEvent": "BEFORE_DOWNLOAD",
  "statusCode": 200,
  "status": "STATUS_SUCCESS",
  "warnings": [],
  "errors": [],
  "debug": []
}

--format table output

jf worker dry-run @payload.json --format table
key          workerKey   triggeredByEvent   statusCode  status          warnings  errors  debug
my-worker    my-worker   BEFORE_DOWNLOAD    200         STATUS_SUCCESS

Deploy JFrog Worker

This command is used to update the worker definition (code, description , filter, secret ...) on your Artifactory instance.

ParameterCommand / Description
Command nameworker deploy
Abbreviationworker d
Command options:
--server-id[Optional] Server ID configured using the config command.
--format[Optional] Use --format json to return the response as JSON. Available from JFrog CLI 2.105.0.
--timeout-ms[Default: 5000] The request timeout in milliseconds.
--no-secrets[Default: false] Do not use registered secrets.

Deploy JFrog Worker Example

Deploy a worker to the server with id my-server.

jf worker server deploy --server-id my-server

--format json output

jf worker server deploy --server-id my-server --format json
{
  "status_code": 200,
  "content": "{\"key\":\"my-worker\",\"version\":\"1\"}"
}

Add Secrets to JFrog Worker

This command is used to edit a worker manifest in order to add or edit a secret that can be used for deployment and/or execution.

Secrets are stored encrypted with a master password that will be requested by the command.

Once secrets are added to the manifest, the master password will be required by the deploy and test-run commands.

ParametersCommands / Description
Command nameworker add-secret
Abbreviationworker as
Command options:
--edit[Default: false] Whether to update an existing secret.
Command arguments:
secret-nameThe secret name

Add Secrets to JFrog Worker Example

Add the secret name my-secret to a worker initialized in the current directory.

jf worker add-secret my-secret

Undeploy JFrog Worker

This command is used to remove a registered worker from you Artifactory instance.

ParameterCommand / Description
Command nameworker undeploy
Abbreviationworker rm
Command options:
--server-id[Optional] Server ID configured using the config command.
--format[Optional] Use --format json to return the response as JSON. Available from JFrog CLI 2.105.0.
--timeout-ms[Default: 5000] The request timeout in milliseconds.
--project-key[Optional] The key of the project that the worker belongs to.
Command arguments:
worker-key[Optional] The worker key. If not provided, it will be read from the manifest.json in the current directory.

Undeploy JFrog Worker Example

Undeploy a worker named my-worker from an Artifactory instance identified by my-server.

jf worker undeploy --server-id my-server my-worker

--format json output

jf worker undeploy --server-id my-server my-worker --format json
{
  "status_code": 200,
  "message": "OK"
}

Execute an HTTP-Triggered Worker

Execute an HTTP-triggered worker.

ParameterCommand / Description
Command nameworker execute
Abbreviationworker exec, worker e
Command options:
--server-id[Optional] Server ID configured using the config command.
--format[Default: json] Output format. Supported values: json, table. Available from JFrog CLI 2.105.0.
--timeout-ms[Default: 5000] The request timeout in milliseconds.
--project-key[Optional] The key of the project that the worker belongs to.
Command arguments:
worker-keyThe worker key. If not provided it will be read from the manifest.json in the current directory.
json-payloadThe json payload expected by the worker. Use - to read the payload from standard input. Use @<file-path> to read from a file located at .

Execute an HTTP-Triggered Worker Example

Execute an HTTP-triggered worker initialized in the current directory, with a payload located in a file named payload.json from the same directory.

jf worker execute @payload.json

Execute an HTTP-triggered worker with a payload from the standard input.

jf worker execute - <<EOF
{
  “a”: “key”,
  “an-integer”: 14
}
EOF

Execute an HTTP-triggered worker by providing the payload as an argument.

jf worker execute ‘{“my”:”payload”}’

--format json output (default)

{
  "key": "my-worker",
  "workerKey": "my-worker",
  "triggeredByEvent": "BEFORE_DOWNLOAD",
  "statusCode": 200,
  "status": "STATUS_SUCCESS",
  "warnings": [],
  "errors": [],
  "debug": []
}

--format table output

jf worker execute @payload.json --format table
key          workerKey   triggeredByEvent   statusCode  status          warnings  errors  debug
my-worker    my-worker   BEFORE_DOWNLOAD    200         STATUS_SUCCESS

List Available Events

This command list all the available events on the platform.

ParameterCommand / Description
Command nameworker list-event
Abbreviationworker le
Command options:
--server-id[Optional] Server ID configured using the config command.
--format[Default: table] Output format. Supported values: table, json. Available from JFrog CLI 2.105.0.
--timeout-ms[Default: 5000] The request timeout in milliseconds.
--project-key[Optional] List events available to a specific project.

List Available Events Example

List event supported by a server identified by my-server.

jf worker list-event --server-id my-server

--format table output (default)

name                  label                     supportedFilterCriteria
BEFORE_DOWNLOAD       Before Download           repoPath,repoKey
AFTER_CREATE          After Artifact Created    repoPath,repoKey
GENERIC_EVENT         Generic Event

--format json output

jf worker list-event --server-id my-server --format json
[
  {
    "name": "BEFORE_DOWNLOAD",
    "label": "Before Download",
    "supportedFilterCriteria": ["repoPath", "repoKey"]
  },
  {
    "name": "AFTER_CREATE",
    "label": "After Artifact Created",
    "supportedFilterCriteria": ["repoPath", "repoKey"]
  }
]

List Registered Workers

List workers saved on your Artifactory instance. The default output is a table (CSV) with columns name, action, description, enabled, sorted by worker name. Use --format json for full JSON output.

⚠️

Warning

The --json boolean flag has been removed as of JFrog CLI 2.105.0 and replaced by --format json. If your scripts use --json, update them to use --format json.

ParameterCommand / Description
Command nameworker list
Abbreviationworker ls
Command options:
--server-id[Optional] Server ID configured using the config command.
--format[Default: table] Output format. Supported values: table, json. Available from JFrog CLI 2.105.0.
--timeout-ms[Default: 5000] The request timeout in milliseconds.
--project-key[Optional] List the events created in a specific project.

List Registered Workers Example

List all workers registered in a platform named my-platform.

jf worker list --server-id my-platform

--format table output (default)

my-worker,BEFORE_DOWNLOAD,Intercepts download requests,true
another-worker,AFTER_CREATE,Post-creation hook,false

--format json output

jf worker list --server-id my-platform --format json
{
  "workers": [
    {
      "key": "my-worker",
      "description": "Intercepts download requests",
      "debug": false,
      "enabled": true,
      "sourceCode": "...",
      "action": "BEFORE_DOWNLOAD",
      "secrets": [],
      "projectKey": ""
    },
    {
      "key": "another-worker",
      "description": "Post-creation hook",
      "debug": false,
      "enabled": false,
      "sourceCode": "...",
      "action": "AFTER_CREATE",
      "secrets": [],
      "projectKey": ""
    }
  ]
}

Show Worker Execution History

Display the execution history of a specific worker.

ParameterCommand / Description
Command nameworker execution-history
Abbreviationworker exec-hist, worker eh
Command options:
--server-id[Optional] Server ID configured using the config command.
--format[Default: json] Output format. Supported values: json, table. Available from JFrog CLI 2.105.0.
--timeout-ms[Default: 5000] The request timeout in milliseconds.
--project-key[Optional] List events available to a specific project.
--with-test-runs[Default: false] Whether to include test-runs entries.
Command arguments:
worker-key[Optional] The worker key. If not provided, it will be read from the manifest.json in the current directory.

Show Worker Execution History Example

Retrieves the execution history of a worker named my-worker, including test runs.

jf worker execution-history --with-test-runs my-worker

--format json output (default)

[
  {
    "workerKey": "my-worker",
    "workerType": "BEFORE_DOWNLOAD",
    "workerProjectKey": "",
    "executionStatus": "STATUS_SUCCESS",
    "startTimeMillis": 1730460000000,
    "endTimeMillis": 1730460001234,
    "triggeredBy": "[email protected]",
    "testRun": false,
    "executedVersion": "3",
    "traceId": "abc123def456"
  }
]

--format table output

jf worker execution-history --with-test-runs my-worker --format table
Worker Key   Worker Type       Project Key  Status          Started At            Ended At              Triggered By          Test Run  Executed Version  Trace ID
my-worker    BEFORE_DOWNLOAD                STATUS_SUCCESS  2024-11-01T12:00:00Z  2024-11-01T12:00:01Z  [email protected]      false     3                 abc123def456

Edit Worker Schedule

Edit the manifest of a SCHEDULED_EVENT worker to update the schedule criteria.

The worker should be deploy afterward with jf worker deploy for the change to be applied to the server.

ParameterCommand / Description
Command nameworker edit-schedule
Abbreviationworker es
Command options:
--cron[Mandatory] A standard cron expression with minutes resolution. Seconds resolution is not supported by Worker service.
--timezone[Default: UTC] The timezone to use for scheduling.

Edit Worker Schedule Example

Edit a worker manifest so that it is executed every minute.

jf worker edit-schedule --cron "* * * * *"