Creating a Multi-Cloud DevOps Extension

Updated 1 week ago by Copado Solutions

Multi-Cloud enables you to implement a DevOps process to work with different clouds. Copado provides some extensions out of the box, but if you want to work with a platform that is not already supported, you can create your own custom extension.

Building a Multi-Cloud DevOps extension is not that difficult. However, there are some steps you need to take and perform in order. In this article, we will guide you through the step-by-step process of building an extension, using Heroku as an example. Let’s get down to the nitty-gritty.

Creating the Copado Records

The first thing you need to do is create the different records in Copado. Copado’s Multi-Cloud extension packages include two job templates that handle the promotion and deployment processes. Each of these job templates consists of a Function step.  Let’s take a look at the step-by-step process.

Promotion Job Template

As mentioned before, the promotion job template includes a Function step. The function involved in the promotion part is similar in all clouds. You can create your promote function using the same script and parameters of the MuleSoft or Heroku promote function.

  1. Give your function a name (e.g., Heroku Promote) and an API name (e.g., heroku_promote).
  2. Provide a description and a version, if desired
  3. Enter the core Copado image: us.gcr.io/copado/copado-function-core:v1. For more information about all the images available, see the Function Images article.
  4. In this case, you don’t need to fill in any other fields, so click on Save.
  5. In the Script tab, paste the below script:
    git_depth=${git_depth:-100}  # set a default git depth of 100 commits
    merge_strategy=${merge_strategy-theirs} # set default merge strategy to ours (only if unset)
    if [ -n "$merge_strategy" ]; then merge_strategy_option=(-X "$merge_strategy"); else merge_strategy_option=(); fi

    echo "promotion branch: $promotion"
    echo "merge strategy: $merge_strategy"
    echo "user stories: $user_stories"
    echo "git_depth: $git_depth"
    copado --progress "fetching $target_branch"
    copado-git-get --depth "$git_depth" "$target_branch"
    copado-git-get --depth "$git_depth" --create "$promotion"
    branches=$(echo "$user_stories" | jq -c -r '.[]')
    for user_story in ${branches[@]}; do
    echo "merging $user_story"
    copado-git-get --depth "$git_depth" "$user_story"
    git checkout "$promotion"
    git merge "${merge_strategy_option[@]}" -m "auto resolved $user_story win over $promotion" "$user_story"
    done

    copado --progress "pushing $promotion $tag"

    if [ -n "$tag" ]; then
    git tag "$tag"
    git push --atomic origin "$promotion" "$tag"
    else
    echo "no tag specified"
    git push origin "$promotion"
    fi
  6. Next, go to the Parameters tab and enter the following parameters:
    Promote Function Parameters
    For more information about the parameters you can reference in a function and other expressions available, review the article Dynamic Expressions (New).
  7. Once you have the function, create the promotion job template (review the Job Template Overview article for more information about job templates) and add a Function step with the function you previously created.

The template should look like this:

Heroku Promote Job Template

Deployment Job Template

The deployment job template also contains a Function step. All you need to build before the job template is the deployment function. To do that, follow these steps:

  1. Give your function a name (e.g., Heroku Deploy) and an API name (e.g., heroku_deploy).
  2. Provide a description and a version, if desired.
  3. Enter the core Copado image: us.gcr.io/copado/copado-function-core:v1.
  4. In this case, you don’t need to fill in any other fields, so click on Save.
  5. In the Script tab, copy the below script:
copado --progress "fetching $promotion"
copado-git-get "$promotion"
copado --progress "deploying $app_name"
dpl --provider=heroku --api_key="$heroku_api_key" --app="$app_name"
copado-git-get --depth 100 "$target_branch"
git merge "$promotion"
git push origin "$target_branch"
  1. Next, go to the Parameters tab and enter the required parameters. In this Heroku example, we need the following parameters:
    Heroku deploy function parameters
  2. Once you have the function, create the deployment job template and add a Function step with the function you just created.

Depending on the extension you are building, you may need to create additional records. If that’s the case, go ahead and do that before proceeding to the next step. For the Heroku example we are using here, we don’t need anything else, so we can go ahead and create the JSON file.

You should test your functions and make sure they work as expected before moving on to the next step.

Generating the JSON File

Salesforce doesn’t allow you to include data records in a package. Therefore, you need to create a static resource to store the data records you have created in the previous section and generate a JSON file for the data records that will be included in the static resource. Let’s go ahead and generate the JSON file.

  1. Navigate to the Copado Extensions tab.
  2. Click on the Create Extension subtab to start the process.
  3. Now, you need to select the job template, job steps and functions you have previously created: From the Select Object picklist field:
    1. Select Job Template and use the Select record field to locate the promotion and the deployment job templates you created in the previous section.
    2. Select Job Step and add the promote and deploy steps.
    3. Select Function and add the promote and deploy functions:
    Extension Records
  4. Once you are done, click on Create Extension.
  5. Copado generates a JSON string. Click on the copy icon at the top right corner to copy it:
    Copy JSON String
  6. Save this file on your laptop as a .json file.
  7. Optionally, edit the content of the document and replace “copado__Type__c: “Custom” with “copado__Type__c”: “Standard”.
    This will prevent functions from being modified in orgs where the extension package is installed.

Creating the Static Resource

You have your JSON file. Now, you need to create the static resource. To do that, follow these steps:

  1. Navigate to Setup > Static Resources and click on New to create a new static resource.
  2. Give your static resource a meaningful name, e.g., HerokuExtensionBundle.
  3. Provide a description if desired.
  4. Select the JSON file you created previously.
  5. Leave the Cache Control picklist as is. 
  6. Click on Save.
    Static Resource record

Creating the StandardResource Custom Metadata Type Record

Once you have created the static resource, the next step is to create a new StandardResource record and link your static resource to it. Go ahead and follow these steps to create the StandardResource:

  1. Navigate to Setup > Custom Metadata Types.
  2. Click on Manage Resources next to the StandardResources custom metadata type.
  3. Next, click on New to create a new record.
  4. Provide the label for your standard resource.
  5. Provide the name (API name) for your standard resource, e.g., HerokuExtensionBundle.
  6. The provider field references the name of the company or person that is building the extension.
  7. In the Static Resource Name field, provide the name of the static resource you previously created.
    This is what the record should look like:

Creating the Package

In the previous sections, you created the data records and the static and standard resources to store those records. Now, you need to package all that metadata before you can distribute it to your end users. Let’s see how you can do that:

  1. Create a new unlocked package. For more information about how to do this, review Salesforce’s documentation.
  2. This package should include the metadata you have created: the static resource and the StandardResource custom metadata type.
  3. Once you are ready, promote your package from beta to released.

Now that your package is ready to be used, go ahead and learn how to configure the pipeline and the different environments you need to start your DevOps process in Copado. Following the Heroku example we have used in this guide, you can find the step-by-step process in the article Heroku Plugin Configuration Steps.


How did we do?