Acorel
To Acorel.nl
Acorel background

SAP CCV2 – How to do nightly builds and deploys (CI/CD)

Maikel Bollemeijer, 14 October 2020

Continuous integration and continuous delivery or in short CI/CD is a common practice nowadays and therefor a widely adopted way to deliver your software to its intended destination.
CI/CD is commonly used for:

Each of the mentioned use cases come with their own challenges and considerations when employing CI/CD, but ‘consistency is key’ applies to all of them. The actions specified in your CI/CD tool should always operate the same way, making it predictable and repeatable. The goal is to replace procedures of manual actions with automated processes that can be started with the press of a single button (or scheduled).
On the net there are a variety of articles that can be found that will go much deeper into the CI/CD philosophy and will give a more comprehensive explanation on the topic.

I am going to show you how we implemented nightly builds using the following tools.

Let’s start with one big difference in V1 and V2 of the commerce cloud platform.
On V2 you can’t deploy your own build packages, this is simply not possible anymore. In the cloud portal you connect your git repository to the platform and create builds from the web interface SAP provides you with.
This of course has some pros and cons on its own.

Pros

Cons

So how do we deploy through CI/CD onto the V2 cloud platform?

SAP introduced build and deployment APIs at the end of 2019.

Below a copy pasted list from there documentation demonstrating which APIs they made available.

In addition to the above listed items, they also made a CLI tool available called sapccm to be used through a terminal or automated process.
We tried the CLI tool to be used in our CI/CD solution and even locally on our development machine, but we came to the conclusion that this tool was not stable enough to be used in a CI/CD solution. It threw SocketTimeOutExceptions (yes it is written in Java) constantly when waiting on a build process to finish, losing the status of the progress. Progress that was needed to trigger a deploy.

So we decided to write our own CLI tool called SAP CX CLI Acorel (SCCA), scca which consumes the SAP REST API, we also dockerized it so it was easy to use in a CI/CD solution. We won’t go into depth on the code itself but rather on how we used it in our CI/CD solutions.
Although we did decide to make it open source for anyone to benefit from our solutions (Dockerfile included). You can find it on Bitbucket here
Feel free to improve it, use it, make PR, leave feedback or make a suggestion.

We will be discussing the following topics in this example:

  1. Build your code CI/CD (We will not be discussing this)
  2. Trigger a build in SAP Commerce Cloud V2 (And wait for it to finish)
  3. Trigger a deploy on the D1 environment (And forget about it)

We host our projects on Atlassian Bitbucket Cloud and there the CI/CD solution provided is called Bitbucket Pipelines.

When point one is finished we want to build (again), only then on the ccv2 platform and when finished successfully trigger a deployment to the D1 environment, using our own CLI tool in the CI/CD.

Prerequisites

Below an example how we use scca to trigger a build on the CCV2 platform:

- step: &cloud-build
    clone:
      enabled: false
    options:
      size: 1x
    name: Trigger build SAP Cloud
    image:
      name:  /sap-cx-cli-acorel:latest
      aws:
        access-key: $AWS_ACCESS_KEY
        secret-key: $AWS_SECRET_KEY
    artifacts: # defining the artifacts to be passed to each future step.
      - build-output.txt
    script:
      - scca config set --api-token=$SAP_API_TOKEN --sap-subscription-id=$SAP_SUBSCRIPTION_ID
      - scca build create --branch=$BITBUCKET_BRANCH --name=$(echo "$BITBUCKET_BRANCH-$BITBUCKET_BUILD_NUMBER" | sed -e "s/^.*///") > $BITBUCKET_CLONE_DIR/build-output.txt

Lets go over what we see here in the script section of the step.

- scca config set --api-token=$SAP_API_TOKEN --sap-subscription-id=$SAP_SUBSCRIPTION_ID

This configures scca to use the correct API Token and subscription id.
Next we have the build create, there is a lot more going on here.

- scca build create --branch=$BITBUCKET_BRANCH --name=$(echo "$BITBUCKET_BRANCH-$BITBUCKET_BUILD_NUMBER" | sed -e "s/^.*///") > $BITBUCKET_CLONE_DIR/build-output.txt

The reason why we store the output of this create build command is that we need to share de build code generated by SAP CCV2 to the next step, the deploy to the D1 environment. Because this a separate step the docker instance used will be reset and forgets about the earlier progress or tasks it has done. The create build command of scca doing poll for the progress of the build thus when complete the build is done on the SAP platform.

You can skip this by appending the –no-wait to the command.

Now we have build ready to be deployed on the SAP Commerce cloud v2, below an example on how to the build this using scca.
Deploy step

- step: &cloud-deploy
    clone:
      enabled: false
    options:
      size: 1x
    name: Deploy SAP Cloud D1
    image:
        name: <url to your docker image>/sap-cx-cli-acorel:latest
        aws:
          access-key: $AWS_ACCESS_KEY
          secret-key: $AWS_SECRET_KEY
    script:
      - scca config set --api-token=$SAP_API_TOKEN --sap-subscription-id=$SAP_SUBSCRIPTION_ID
      - scca build deploy --build-code=$(grep -Po '(?<=build-code:s).*' $BITBUCKET_CLONE_DIR/build-output.txt) --environment-code=$environment --no-wait

On the first row of the script we are setting the configuration again, just like we did with the creating a build step discussed earlier.The magic happens on the second row, where we use the scca build deploy command.

 - scca build deploy --build-code=$(grep -Po '(?<=build-code:s).*' $BITBUCKET_CLONE_DIR/build-output.txt) --environment-code=$environment --no-wait

When this step is completed bitbucket considers the deploy to be successful.
You may have noticed we did not specify any update strategies and extras like that, thats because scca has some default if not specified but can be overriden by adding the following parameters to the deploy command.

--strategy= The way the deployment is handled [default: ROLLING_UPDATE]
--database-update-mode= DB update mode [default: UPDATE]

Possible options for database update mode are NONE, UPDATE, and INITIALIZE
Possible options for strategy are ROLLING_UPDATE and RECREATE.

Now we are able to build and deploy on the SAP Commerce cloud v2, only thing left is to schedule a nightly trigger.
How to do that can be found here for Bitbucket pipelines

scca sources

Maikel Bollemeijer

Read all my blogs

Receive our weekly blog by email?
Subscribe here: