Create Kubectl plugin procedures

5 minute readExtensibilityDeveloper productivity

Plugin procedures can be used in procedure steps, process steps, and pipeline tasks, allowing you to orchestrate third-party tools at the appropriate time in your component, application process, or pipeline.

Depending on your plugin configuration and how you run procedures, the Input parameters  Configuration name field may behave differently in the CloudBees CD/RO UI. For more information, refer to Differences in plugin UI behavior.

Create Or Update Objects

Create or update Kubernetes objects using kubectl commands to apply, create, and replace based on a specification (either a YAML/JSON file or content provided in a text area). The selected update action determines which kubectl command is used.

Input parameters

Table 1. Create Or Update Objects input parameters
Parameter Description

Configuration name

Required. The previously defined configuration for the plugin.

Update action

Required. Select the appropriate update action.

  • apply: Creates the object if it does not exist or updates the object if it already exists.

  • create: Creates the object if it does not exist.

  • replace: Replaces the object if it exists.

Specification source

Required. Select the specification source.

  • filePath: The file specified in the File path field.

  • fileContent: The text entered in the Content field.

  • kustomizeDirectory: The directory specified in the Kustomization directory field.

File path

Required if the Specification source is filePath. The absolute path to a file with a YAML or JSON specification. For example, /var/myfile.yml.

Content

Required if the Specification source is fileContent. Content for the specification in either a YAML or JSON specification. YAML can contain several sections, separated by ---.

Kustomization directory

Required if the Specification source is kustomizeDirectory. The directory path where the kustomization file is located. For example, /var.

Additional options for kubectl

Additional options for kubectl, separated by newlines. For example, --log-dir or --log-flush-frequency. Additional options can also be provided at the configuration-level. However, no redundancy check is performed if an option is defined in both places.

Additional options for kubectl command

Additional options for kubectl command separated by newlines. For example, for the apply command, use --recursive or --validate.

Result property path

If specified, the command output, error output, and exit value are stored in properties whose names are kubectlCommandOutput, kubectlCommandErrorOutput, and kubectlCommandExitValue, respectively.

Delete Objects

Deletes Kubernetes objects based on a specification (either a YAML/JSON file or content provided in a text area).

Input parameters

Table 2. Delete Objects input parameters
Parameter Description

Configuration name

Required. The previously defined configuration for the plugin.

Specification source

Required. Select the specification source.

  • filePath: The file specified in the File path field.

  • fileContent: The text entered in the Content field.

File path

Required if the Specification source is filePath. The absolute path to a file with a YAML or JSON specification. For example, /var/myfile.yml.

Content

Required if Specification source is fileContent. Content for the specification in either a YAML or JSON specification. YAML can contain several sections, separated by ---.

Kustomization directory

Required if the Specification source is kustomizeDirectory. The directory path where the kustomization file is located. For example, /var.

Additional options for kubectl

Additional options for kubectl, separated by newlines. For example, --log-dir or --log-flush-frequency. Additional options can also be provided at the configuration-level. However, no redundancy check is performed if an option is defined in both places.

Additional options for kubectl command

Additional options for the kubectl delete command, separated by newlines. For example, --force.

Result property path

If specified, the command output, error output, and exit value are stored in properties whose names are kubectlCommandOutput, kubectlCommandErrorOutput, and kubectlCommandExitValue, respectively.

Describe Objects

Use this procedure to describe Kubernetes objects based on a specification (either a YAML/JSON file or content provided in a text area).

Input parameters

Table 3. Describe Objects input parameters
Parameter Description

Configuration name

Required. The previously defined configuration for the plugin.

Specification source

Required. Select the specification source.

  • filePath: The file specified in the File path field.

  • fileContent: The text entered in the Content field.

File path

Required if the Specification source is filePath. The absolute path to a file with a YAML or JSON specification. For example, /var/myfile.yml.

Content

Required if Specification source is fileContent. Content for the specification in either a YAML or JSON specification. YAML can contain several sections, separated by ---.

Kustomization directory

Required if the Specification source is kustomizeDirectory. The directory path where the kustomization file is located. For example, /var.

Output format

The output format, which stands for --output. It must be:

  • yaml

  • wide

  • name

  • custom-columns=…​

  • custom-columns-file=…​

  • go-template=…​

  • go-template-file=…​

  • jsonpath=…​

  • jsonpath-file=…​

For more information, refer to custom columns, golang template and jsonpath template.

Additional options for kubectl

Additional options for kubectl, separated by newlines. For example, --log-dir or --log-flush-frequency. Additional options can also be provided at the configuration-level. However, no redundancy check is performed if an option is defined in both places.

Additional options for kubectl command

Additional options for the kubectl get command, separated by newlines. For example, --ignore-not-found.

Result property path

If specified, the command output, error output, and exit value are stored in properties whose names are kubectlCommandOutput, kubectlCommandErrorOutput, and kubectlCommandExitValue, respectively.

Run Custom Command

Use this procedure to run custom kubectl commands by providing a command and any required parameters. The parameter fields for this procedure use the Kubernetes kubectl syntax.

Input parameters

Table 4. Run Custom Command input parameters
Parameter Description

Configuration name

Required. The previously defined configuration for the plugin.

Kubectl command

Required. The kubectl command to run, in syntax [command] [TYPE] [NAME]:

  • command: Specifies the operation to perform on one or more resources, such as create, get, describe, or delete.

  • TYPE: Specifies the resource type.

  • NAME: Specifies the name of the resource.

For example, get pod dev. For more information, refer to the kubectl documentation.

Flags and parameters for kubectl command

Specify newline-separated and space-delimited flags and parameters, and any output options for your Kubectl command entry. Newline-separated example, for --output yaml:

--output=yaml

Space-delimited example, for -o yaml:

-o yaml

Flags for kubectl

Specify newline-separated and space-delimited flags/options that affect the operation of the kubectl command, such as logging settings or other operational parameters. For example, --log-dir or --log-flush-frequency. For more information, refer to kubectl options. Newline-separated example, for --namespace dev:

--namespace=dev

Space-delimited example, for -n dev:

-n dev
No redundancy checks are performed if an option is defined here and in configuration files.

Specification source

Required. Select the specification source.

  • noSpecification: No specification needs is used.

  • filePath: The file specified in the File path field.

  • fileContent: The text entered in the Content field.

File path

Required if the Specification source is filePath. The absolute path to a file with a YAML or JSON specification. For example, /var/myfile.yml.

Content

Required if Specification source is fileContent. Content for the specification in either a YAML or JSON specification. YAML can contain several sections, separated by ---.

Result property path

If specified, the command output, error output, and exit value are stored in properties whose names are kubectlCommandOutput, kubectlCommandErrorOutput, and kubectlCommandExitValue, respectively.