73 · CI/CD with SAP Build Code

Connect a Git repository, write .pipeline/config.yml with multi-environment stages, and gate production with manual approval.

Episode 73 — CI/CD with SAP Build Code

What you'll learn

Why this matters

Deploying from a developer's laptop is fragile — it depends on local tool versions, CF login state, and network reliability. A proper CI/CD pipeline runs builds in a clean environment, runs tests before deploying, and deploys to multiple environments in sequence. SAP Build Code's CI/CD service is a first-class BTP product that integrates natively with Cloud Foundry and Git, so you don't have to manage Jenkins infrastructure yourself.

What SAP Build Code CI/CD provides

Feature Detail
Predefined pipeline stages Init, Build, Test, Compliance, Deploy
SAP-curated Docker images Pre-installed with mbt, CF CLI, node, java
Git integration GitHub, GitLab, Bitbucket, Azure DevOps
Credential store Encrypted secrets (CF login, service keys)
Blue-green deploy support Native integration with MTA CF Plugin
Audit log Full run history with logs per stage

Setting up a repository connection

  1. BTP Cockpit → Services → SAP Build Code → CI/CD Service
  2. Go to Repositories → Add
  3. Enter repository URL + personal access token (stored encrypted)
  4. Choose branch (e.g. main)

Pipeline configuration: .pipeline/config.yml

Add this file to the root of your repository:

# .pipeline/config.yml
general:
  buildTool: mta

service:
  name: my-cap-app

stages:
  Build:
    mtaBuildTool: cloudMbt   # use mbt from the SAP Build Code image

  Unit-Tests:
    run: true
    npmRunScript: test

  Lint:
    run: true
    npmRunScript: lint

  Integration-Tests:
    run: false             # enable when you have integration tests

  Deploy-to-Dev:
    cfTargets:
      - apiEndpoint: 'https://api.cf.eu10.hana.ondemand.com'
        org:         my-company-dev
        space:       dev
        credentialsId: cf-dev-credentials
        mtaDeployParameters: '-f'

  Deploy-to-Test:
    cfTargets:
      - apiEndpoint: 'https://api.cf.eu10.hana.ondemand.com'
        org:         my-company-test
        space:       test
        credentialsId: cf-test-credentials
        mtaDeployParameters: '-f'
    runTests: true

  Deploy-to-Prod:
    cfTargets:
      - apiEndpoint: 'https://api.cf.eu10.hana.ondemand.com'
        org:         my-company-prod
        space:       production
        credentialsId: cf-prod-credentials
        mtaDeployParameters: '--strategy blue-green'
    manualConfirmation: true    # human gate before prod deploy

Adding CF credentials to the pipeline

In CI/CD Service → Credentials → Add:
- Type: Basic Authentication
- Name: cf-prod-credentials
- Username: technical user email
- Password: technical user password

The pipeline uses these credentials for cf login — they are never exposed in pipeline logs.

Triggering the pipeline

The pipeline triggers automatically on push to the configured branch. You can also trigger manually from the CI/CD UI.

Pipeline stages run in order:

Init → Build → Unit-Tests → Lint → Deploy-to-Dev → Deploy-to-Test → [Approval] → Deploy-to-Prod

If any stage fails, the pipeline stops and notifies you via email (configurable).

Using GitHub Actions as an alternative

If your team already uses GitHub Actions, you can replicate the same flow:

# .github/workflows/deploy.yml
name: Deploy CAP App

on:
  push:
    branches: [main]

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    container:
      image: mcr.microsoft.com/devcontainers/base:ubuntu

    steps:
      - uses: actions/checkout@v4

      - name: Install tools
        run: |
          npm install -g mbt
          wget -q "https://packages.cloudfoundry.org/stable?release=linux64-binary&version=v8&source=github" -O /tmp/cf.tgz
          tar -xzf /tmp/cf.tgz -C /usr/local/bin
          cf install-plugin multiapps -f

      - name: Build MTA
        run: mbt build -t ./

      - name: CF Login
        run: |
          cf api ${{ vars.CF_API }}
          cf auth "${{ secrets.CF_USER }}" "${{ secrets.CF_PASSWORD }}"
          cf target -o "${{ vars.CF_ORG }}" -s "${{ vars.CF_SPACE }}"

      - name: Deploy
        run: cf deploy *.mtar -f

Store CF_USER and CF_PASSWORD in GitHub Secrets, org/space/API in Variables.

Common mistakes

Mistake Fix
Committing CF credentials to the repo Use CI secrets / credential store
No test stage before deploy Tests must run before any CF deploy
Deploying directly to prod on every push Gate prod deploys with manual approval
Using personal user accounts as CI credentials Create a technical CF user with minimal roles
No rollback step Document the rollback command and who can run it

Checkpoint ✓

You can connect a Git repository to SAP Build Code CI/CD, write a .pipeline/config.yml with build, test, and multi-environment deploy stages, add CF credentials securely, and gate production deployments with a manual approval step.

Sign in for progress tracking & Q&A →