Example Function Scripts

Updated 5 days ago by Copado Solutions

In this article, you will find some out-of-the-box scripts you can execute as part of a function to complete different tasks.

Before you get to executing advanced scripts, it is a good practice to do a test and ensure you have all the necessary permissions to run a function. You can use the below basic script:

echo hello world $name

If there are any problems, you can troubleshoot them before moving on to running more advanced functions. 

Clone a public Git repository and review its size:

copado -p 'Cloning the repository' 
mkdir repo 
cd repo 
git clone "$giturl" . 
copado -p 'Running git-sizer'
git-sizer --verbose > git-sizer.txt 
git-sizer --json > git-sizer.json 
copado -p 'Attaching results' 
copado -u git-sizer.txt 
copado -u git-sizer.json

To clone a public repository, you need to add the URL in the Parameters section.

Clone a private repository and review its size:

# 1 - Clone Git Branch
echo "$provider"
copado --progress "Cloning the repository"
copado-git-get -d . "$branchName"

# 2 - Run Git Sizer Library
copado --progress "Running git-sizer"
git-sizer --verbose > git-sizer.txt
git-sizer --json > git-sizer.json

# 3 - Attach Output Files in the Copado Result record
copado --progress "Attaching results"
copado --u git-sizer.txt
copado --u git-sizer.json

In the case of a private repository, you need to provide the credentials. To avoid exposing these credentials, use the following dynamic parameter:

{$Context.Repository.Credential} (if you are in a version older than v18.23.1, use {$RecordId.Repository.Credential} instead).

To run this script, you also need to provide the branch name and the Git provider as parameters, so configure them as follows:


  • Parameter Name: branchName
  • Default Value: master (main if you are working with GitHub).


  • Parameter Name: provider
  • Default Value:  {$Context.Git_Provider__c} (if you are in a version older than v18.23.1, use {$RecordId.Git_Provider__c} instead).

This parameter needs to be sent as a git_json, otherwise, the backend won’t understand it and the copado-git-get command will fail.

In addition to these scripts, there are some out-of-the-box commands you can include in your scripts. For more information about this, please review the article Example Function Commands.

How did we do?