Skip to content

Latest commit

 

History

History
360 lines (215 loc) · 14.2 KB

File metadata and controls

360 lines (215 loc) · 14.2 KB

Set Up a CI/CD Pipeline for SAP BTP, Cloud Foundry Runtime

In this tutorial, you learn how to initialize a repository in SAP Business Application Studio and how to set up your CI/CD pipeline.

Prerequisites

This tutorial follows the guidance provided in the SAP BTP Developer's Guide.

Create a repository

To be able to perform the steps for setting up a CI/CD pipeline, you need a public repository. Currently, SAP Continuous Integration and Delivery supports GitHub and Bitbucket repositories.

For real application development, you need to consider the right place for your repository.

In this example, we're creating a repository on GitHub. You need a GitHub account for this step. Go ahead and create one if you don't have it yet.

  1. Create a new GitHub repository in your GitHub account.

  2. Under Repository name, enter incident-management.

  3. Choose Create repository.

    Create repository

  4. You're directed to the Quick Setup page of your new repository. Make sure to copy the URL of the repository as you'll need it in the next steps.

    Quick Setup

Initialize a repository in SAP Business Application Studio

  1. In SAP Business Application Studio, navigate to Source Control and choose Initialize Repository.

    Initialize repository

  2. In the dropdown Pick workspace folder to initialize git repo in, choose the incident-management folder.

    Pick workspace folder

  3. Open the three dots menu next to Source Control and choose RemoteAdd Remote....

    Add remote

  4. Paste the URL of your repository in the Provide repository URL field and press Enter.

    Provide repo URL

  5. Provide a remote name and press Enter.

    Provide remote name

  6. Stage your changes, add a commit message, and choose Publish Branch.

    Publish branch

  7. Provide your GitHub username and password when prompted. When the changes are pushed, you see your project in your GitHub repository.

Enable SAP Continuous Integration and Delivery Service

  1. Navigate to your subaccount and choose ServicesService Marketplace on the left.

  2. Type Continuous Integration & Delivery in the search box and choose Create.

    Continuous Integration and Delivery create service

  3. Choose Create in the New Instance or Subscription popup without changing any values.

    New Instance or Subscription popup

  4. Choose View Subscription and wait until the status changes to Subscribed.

    View subscription

    Status subscribed

  5. In your SAP BTP subaccount, choose SecurityRole Collections in the left-hand pane.

  6. Choose role collection CICD Service Administrator.

  7. Choose Edit.

    Edit role

  8. In the Users section, enter your user and select the icon to add the user.

    Add user

    Keep the setting Default Identity Provider unless you have a custom identity provider configured.

  9. Choose Save.

    You've assigned the CICD Service Administrator role collection to your user.

Log out and log back in to make sure your new role collection is considered.

See Initial Setup for more details on how to enable the service.

Access SAP Continuous Integration and Delivery Service

  1. In your SAP BTP subaccount, navigate to ServicesInstances and Subscriptions in the left-hand pane.

  2. Choose Continuous Integration & Delivery.

    CI/CD Go to application

  3. Use your SAP BTP global user name and global password to log in to the application.

Add Credentials

  1. Choose the Credentials tab and choose the icon to add a new credential.

    Add new credential

  2. Under Create Credentials on the right:

    • Enter github in the Credential Name field.
    • Choose Basic Authentication from the dropdown in the Type field.
    • Enter your GitHub user name in the Username field.
    • Enter your GitHub personal access token in the Password field.
    • Choose Create.

    See Create a Credential for a Private GitHub Repository for instructions on how to create a GitHub personal access token if you don't have one.

    Create GitHub credential

  3. Choose the icon to add a new credential again and create a credential for Cloud Foundry:

    • Enter cf in the Credential Name field.
    • Choose Basic Authentication from the dropdown in the Type field.
    • Enter your SAP BTP global user name in the Username field.
    • Enter your SAP BTP global password in the Password field.
    • Choose Create.

    configure pipeline

Add a CI/CD job

  1. Navigate to the Jobs tab and choose the icon to add a new job.

    Add new job

  2. Enter Incident-Management in the Job Name field.

Add repository

  1. Open the value help for the Repository field.

    Add job name

  2. In the Select Repository popup, choose Add Repository. A popup opens.

    Select Repository popup

  3. In the Add Repository popup, enter details for the repository you created in Step 1: Create a repository:

    • Enter incident-management in the Name field.
    • Enter your repository's URL in the Clone URL field.
    • Open the value help in the Credentials field and choose the credential github that you created in Step 5: Add credentials.
    • Select GitHub from the dropdown in the Type field.

    Add Repository popup

Create credentials

  1. Open the value help in the Webhook Credential field.

    Create Webhook value help

  2. In the Select Credentials popup, choose Create Credentials.

    Select Credentials popup

  3. In the Create Credentials popup:

    • Enter webhook in the Credentials Name field.
    • Click Generate next to the Secret field to create a secret.
    • Copy the generated secret from the Secret field and save it. You need it in Step 7: Create a GitHub webhook.
    • Choose Create.

    Create webhook

  4. Go back in the Add Repository popup and choose Add to complete the addition of a repository.

    Complete repo addition

Configure pipeline and stages

Node.js
  1. Back in the General Information tab, enter main in the Branch field.

  2. Select Cloud Foundry Environment from the dropdown in the Pipeline field.

    Configure pipeline

  3. In the Stages section, select mta from the dropdown in the Build Tool field.

  4. Select the latest Java and Node version from the dropdown in the Build Tool Version field.

    Configure stages

Add unit tests and configure release

  1. In the Additional Unit Tests section, switch the toggle button to ON.

  2. Enter test in the npm Script field.

    Add unit tests

  3. In the Release section, switch the toggle Deploy to Cloud Foundry Space to ON.

  4. Provide the required information for your account and complete the job creation:

    • Enter the URL of your API endpoint in the API Endpoint field.

    • Enter the name of your Cloud Foundry organisation in the Org Name field.

    • Enter the name of your development space in the Space field.

      You can get the values from your subaccount's Overview page in the SAP BTP cockpit.

    • Select standard from the dropdown in the Deploy Type field.

    • Open the value help in the Credentials field and choose the credential cf that you created in Step 5: Add credentials.

    • Choose Create.

    Configure release

Java
  1. Back in the General Information tab, enter main in the Branch field.

  2. Select Cloud Foundry Environment from the dropdown in the Pipeline field.

    Configure pipeline

  3. In the Stages section, select mta from the dropdown in the Build Tool field.

  4. Select the latest Java and Node version from the dropdown in the Build Tool Version field.

    Configure stages

Configure release

  1. In the Release section, switch the toggle Deploy to Cloud Foundry Space to ON.

  2. Provide the required information for your account and complete the job creation:

    • Enter the URL of your API endpoint in the API Endpoint field.

    • Enter the name of your Cloud Foundry organisation in the Org Name field.

    • Enter the name of your development space in the Space field.

      You can get the values from your subaccount's Overview page in the SAP BTP cockpit.

    • Select standard from the dropdown in the Deploy Type field.

    • Open the value help in the Credentials field and choose the credential cf that you created in Step 5: Add credentials.

    • Choose Create.

    Configure release

Create a GitHub webhook

  1. Navigate to the Repositories tab and choose the incident-management repository that you created. Under the Webhook Event Receiver tab, choose Webhook Data.

    Incident-Management repo

  2. In the Webhook Creation popup, find the Payload URL field and copy its value.

    Webhook Data popup

  3. Go to your repository on GitHub and open the Settings tab.

  4. From the navigation pane on the left, choose WebhooksAdd webhook.

    Add webhook

  5. Insert the data for your webhook:

    • Paste the incident-management repository's payload URL that you copied from the Webhook Creation popup in the Payload URL field.
    • Select application/json from the dropdown in the Content type field.
    • Paste the secret that you created in Step 6: Add a CI/CD job in the Secret field.
    • Under Which events would you like to trigger this webhook, select Just the push event.
    • Choose Add webhook.

    Configure webhook

Test your job

  1. You have to trigger your job manually the first time after creation. Go back to the SAP Continuous Integration and Delivery application and navigate to the Jobs tab.

  2. Choose the Incident-Management job and choose Run.

    Run job

  3. Verify that a new tile appears in the Builds view. This tile is marked as running.

    Build running

  4. Wait until the job has finished and verify that the build tile is marked as successful.

    Build successful