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 two extensions out of the box, MuleSoft and Heroku, and there will be more coming in the future. 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 automation templates that handle the promotion and deployment processes. Each of these automation templates consists of a Salesforce Flow step and a Function step.  Let’s take a look at the step-by-step process.

Promotion Automation Template

As mentioned before, the promotion automation template includes a Salesforce Flow step and a Function step:

  1. The flow step collects the user stories included in the promotion and the promotion branch name and saves this information in a variable. This flow is the same for all the extensions, thus, you can reuse the existing copado.Get Promotion User Story Names flow available in the Copado deployer package.
  2. 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, copy the below script:
      git_depth=${git_depth:-100}  # set a default git depth of 100 commits
      promotion_branch="promotion/$promotion"
      echo "promotion: $promotion"
      echo "promotion branch: $promotion_branch"
      echo "user stories: $user_stories"

      copado --progress "fetching $target_branch"
      copado-git-get --depth "$git_depth" "$target_branch"
      copado-git-get --depth "$git_depth" --create "$promotion_branch"

      for user_story in ${user_stories//,/}
      do
      echo "merging feature/$user_story"
      copado-git-get --depth "$git_depth" "feature/$user_story"
      git checkout "$promotion_branch"
      git merge -X ours -m "auto resolved feature/$user_story win over $promotion_branch" "feature/$user_story"
      done

      copado --progress "pushing $promotion_branch $tag"

      if [ -n "$tag" ]; then
      git tag "$tag"
      git push --atomic origin "$promotion_branch" "$tag"
      else
      echo "not tag specified"
      git push origin "$promotion_branch"
      fi
    6. Next, go to the Parameters tab and enter the following parameters:
      Heroku Promote Parameters
      For more information about the parameters you can reference in a function and other expressions available, review the article Dynamic Expressions.
  3. Once you have the function, create the promotion automation template (review the AutomationTemplates article for more information about how to do this) and add a Salesforce Flow step that should contain the copado.Get Promotion User Story Names flow and a Function step with the function you previously created.

The template should look like this:

Heroku Promote template

Deployment Automation Template

The deployment automation template also contains a Salesforce Flow step and a Function step. The flow is the same as that of the promotion and is used to pass promotion data to the function. All you need to build before the automation 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:
branch="promotion/$promotion"
copado --progress "fetching $branch"
copado-git-get $branch
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 $branch
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 Parameters

  1. Once you have the function, create the promotion automation template and add a Salesforce Flow step that should contain the copado.Get Promotion User Story Names flow and 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. From the Select Object picklist field, select Deployment and use the Select record field to locate the promotion and the deployment automation templates you created in the previous section:
    Copado Extensions tab
  4. Once you are done, click on Generate bundle:
    Generate Bundle button
  5. Copado generates a JSON string. Click on the copy icon at the top right corner to copy it:
    Copy icon
  6. Save this file on your laptop as a .json file.

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:
StandardResource record

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?