In this exercise, we will create a project in a public GitHub repository in which to store your source code, enable SAP Continuous Integration and Delivery and configure and run a predefined Continuous Integration and Delivery (CI/CD) pipeline that automatically tests, builds, and deploys your code changes.
After completing these steps, you will have created a public GitHub repository, in which you can store the source code of your project. Note: For this execise, you need to have a GitHub user.
-
Open and sign in to https://github.com/.
-
In the Repositories tab, choose New to create a new repository.
-
As Repository name, enter RiskManagement. Don't tick any of the Initialize this repository with checkboxes.
After completing these steps, you will have created a personal access token to authenticate against GitHub.
To create a personal access token, which you can use instead of a password, follow the steps described in Creating a personal access token.
After completing these steps, you will have added your CAP project sources to your GitHub repository.
- If you have Business Application Studio still open from the former exercises, return to it. If you haven't, open your SAP BTP Trial and choose the Quick Tool Access icon SAP Business Application Studio.
-
Open the previously created workspace with your CAP application.
-
Open a new terminal and navigate to your project root folder.
-
Enter your email address and username. You can use the email address that you've used to register your GitHub account:
git config --global user.email "[email protected]" git config --global user.name "Your Name"
-
To initialize a GitHub repository and add the project sources to it, execute the following commands:
git init git add . git commit -m "Push project content to GitHub" git branch -M main
-
Now, add your copied GitHub repository URL from exercise 3.1 as remote repository (without the angle brackets '<' and '>' ):
git remote add origin <copied Git repository url.git>
-
Push the commit with your project content to this GitHub repository:
git push -u origin main
-
When prompted, enter your GitHub username and the personal access token, created in exercise 3.2.
After completing these steps, you will have subscribed to SAP Continuous Integration and Delivery and assigned the Administrator role to your user.
-
Enter your SAP BTP trial account, press Enter Your Trial Account, press on the trial tile and navigate to the Subscriptions tab. Go to Service Marketplace.
-
Type Continuous Integration & Delivery in the search box and choose the service tile:
-
In your SAP BTP subaccount, choose Security → Trust Configuration.
-
Choose the name of your identity provider (For example, 'Default identity provider' in this case).
-
Enter your email address.
-
Choose Show Assignments. (If your user is new to your subaccount, choose Add User in the confirmation dialog.)
-
Choose Assign Role Collection.
-
From the drop-down list, choose CICD Service Administrator.
After completing these steps, you will have configured credentials for connecting SAP Continuous Integration and Delivery to other services.
-
In your SAP BTP subaccount navigate to Services and then to Instances and Subscriptions.
-
Choose the Go to Application icon located next to the Continuous Integration & Delivery subscription.
-
Use your credentials to log in to the application.
-
If your GitHub repository is private, configure credentials for it, so that the Continuous Integration & Delivery service can connect to it. (Note: If your GitHub repository isn't private, you can skip this step.)
-
In the Credentials tab in SAP Continuous Integration and Delivery, choose + (Create Credentials).
-
For Name, enter a freely chosen name for your credential, which is unique in your SAP BTP subaccount. In this example, the name of the credential is github.
-
As Type, select Basic Authentication.
-
For Username, enter your Github username.
-
For Password, use the personal access token, which you've created in GitHub in exercise 3.3.
-
-
To create credentials for deploying to the SAP Cloud Foundry environment, go to the Credentials tab and choose + (Create Credentials).
-
For Name, enter a freely chosen name for your credentials, which is unique in your SAP BTP subaccount. In this example, the name of the credentials is cfdeploy.
-
As Type, select Basic Authentication.
-
For Username, enter your username for the SAP BTP cockpit.
After completing these steps, you will have configured a job in SAP Continuous Integration and Delivery.
-
In the Jobs tab in SAP Continuous Integration and Delivery, choose + (Create Job).
-
For Job Name, enter a freely chosen name for your job, which is unique in your SAP BTP subaccount. In this example, the name of the job is RiskManagment.
-
For Repository, choose Repository and enter a name and the URL of your GitHub repository.
-
For Branch, enter the GitHub branch from which you want to receive push events. In this example, the name of the branch is main.
-
As Pipeline, choose SAP Cloud Application Programming Model.
-
Choose Create.
If the Webhook Creation pop-up, which provides you with the data needed to define a webhook in GitHub, doesn't appear automatically, you can open the detailed view of an existing job in the Jobs tab and under General Information, choose Risk Management.
Then choose Webhook Data.
The following pop-up window appears:
-
Leave it open and, in your project in GitHub, go to the Settings tab.
-
From the navigation pane, choose Webhooks.
-
Enter the Payload URL, Content type, and Secret from the Webhook Creation pop-up in SAP Continuous Integration and Delivery. For all other settings, leave the default values.
After completing these steps, you will have configured the stages of your pipeline in SAP Continuous Integration and Delivery.
- In the GitHub repository of your project (or in your still open Business Application Studio), create a folder named
.pipeline
, which contains a file namedconfig.yml
. In theconfig.yml
file, add the following initial configuration:
# Project configuration
general:
projectName: 'RiskManagement'
productiveBranch: 'main'
# Stage configuration
stages:
productionDeployment:
cfTargets:
- org: '<YOUR ORG NAME>'
space: '<YOUR SPACE NAME>'
appName: '<NAME OF YOUR APPLICATION>'
apiEndpoint: '<YOUR CLOUD FOUNDRY API ENDPOINT>'
credentialsId: '<NAME OF YOUR CEDENTIAL>'
-
Replace the placeholders with the values of the space in the Cloud Foundry environment to which you want to deploy.
<NAME OF YOUR APPLICATION>
isRiskManagement
andcredentialId
is the name of the credentials you have created before for Cloud Platform access, in the example we usedcfdeploy
. You can get the values for<YOUR ORG NAME>
,<YOUR SPACE NAME>
, and<YOUR CLOUD FOUNDRY API ENDPOINT>
from your subaccount overview in the SAP BTP cockpit: -
Commit your changes to GitHub. If you have added the new folder and file in the Businss Application Studio, you can do so by opening a new terminal from the new
.pipeline
folder and then by typing
cd .pipeline
git add -A
git commit -m "new pipeline"
git push
After completing these steps, you will have monitored the outcome of your job in SAP Continuous Integration and Delivery.
-
In the Jobs tab in SAP Continuous Integration and Delivery, select your job and verify that a new tile appears in the Builds view. This tile should be marked as running. Note: If no new tile appears, trigger the job manually by choosing the Trigger Build button.
-
Wait until the job has finished and verify that the build tile is marked as successful.
After completing these steps, you will have accessed your deployed application trough the SAP BTP cockpit.
As we set it up this way, the deployed service can only be accessed when your user has a corresponing role collection assiged. If you tried to open the application without this authorization you would get a Forbidden pop-up. So, you need to assign the role collection to your user:
- In your trial account in the SAP BTP cockpit, navigate to the Security tab and choose Trust Configuration. Choose the Default Entity Provider link.
- Enter the email address for your SAP BTP account (the one you used to log on) and press the Show Assignments button. Then press the Assign Role Collection button and choose RiskManager-dev in the dropdown box. Press the Assign Role Collection button
Now you are ready to access the application!
-
In the left pane of your trial accoun, navigate to the Cloud Foundry tab and choose Spaces.
-
Select your space.
-
Verify that the RiskManagment application has been deployed and that the
Riskmanagement-approuter
is running (might have ablue
or something similar in the name as well like in the picture). -
Choose the
Riskmanagement-approuter
. -
Verify that the deployed application is running and showing its home screen.
-
Press the Risks tile and then in the application the Go button and you should see the final deployed application with the data:
You've created a project in GitHub to store your source code and successfully configured and run a predefined continuous integration and delivery pipeline that automatically builds, tests and deploys your code changes.