Building a Function

Updated 11 hours ago by Copado Solutions

In the article Introduction to Functions, you have learned about functions and the benefits they can bring to your organization. Now that you know what a function is, let's see how you can create a new function.

In order for you to be able to build and run a function, you need the following:

  • The Copado Functions permission set.
  • An API key.
  • An Admin or User license.
  • The Flow User checkbox selected for your user (this is required for non-sys admin users only).
  • You also need to whitelist some Copado IP addresses, especially if your Git repository is protected by a firewall. For more information about this, please review the IP Addresses article.

To start building your function, follow these steps:

  1. Navigate to the Functions tab and click on New.
  2. In the Information section, you can provide general information about your function:
    1. Give your function a name and provide a unique API name.
    2. Select a function type. The available options are Standard or Custom.
    3. Provide a description of what the function does.
    4. Add a version number, if desired.

Function Information

  1. In the Configuration section, you need to add the image to be used by the function. You can also further configure your function and add a timeout or a callback:
    1. Image Name: An image is a container of pre-installed apps and features needed to perform a particular function. Copado provides different images so that you don’t need to invest time installing and configuring the applications or features required to run a function. For more information about all the images available and what they include, see the article Function Images.

      The function core image is:
    2. Timeout: Every time a function is executed, Copado creates a Result record with the function execution details and sets the status to In Progress until the job is completed. If you want Copado to update the status to Failed if there is no response from the function’s job after a certain period of time (e.g., 60 minutes), you can define it here.
    3. Worker Size: Adjust the default worker size if needed.
      Configuration Section
  2. Copado enables you to execute an action once the function has run, which you can define in the Callback section. For instance, if you are running a scan, you can trigger a flow afterwards that posts to chatter if the scan has been successful. Copado passes to the flow result and function as record variables and status as text variable:

Important considerations about callbacks:
Callbacks are executed by an automated process, and automated processes cannot send an email. If you want to trigger a flow that sends a notification, you need to use a Post to Chatter action.

If you want to call an Apex class, the class must be a global class.
  1. Once you have defined the callback, click on Save.
  2. Next, navigate to the Script tab and provide the script with the commands you would like the function to execute:
    Script tab

The script provided in the example above clones a public Git repository and reviews its size (for additional script samples, please check the article Example Scripts and Commands for Functions).

  1. The minimum requirements to run a function are the script and the image. However, some functions require additional parameters. For instance, for the Git repository clone example above, you need to provide a public repository. You can define these parameters in the Parameters tab:
Parameters Tab

Copado supports different types of parameters. For more information about this, review the Dynamic Expressions article.

Alright, you have built your function. Now, you can go ahead and execute it. To learn more about all the options you have to execute a function, review the article Executing a Function.

How did we do?