Tuesday 14 November 2017

Continuous Integration in ABAP using Jenkins

The team has setup a CI/CD pipeline in Jenkins to automate build, test, and deploy of those Java services. At the time we had the pipeline, I have realized the benefits for having such pipeline and that became my motivation to build one for ABAP.

The most important benefit in my view is the visibility over your software’s health. If someone asks whether the Java piece is working fine at the moment, we can have a glance at Jenkins monitor and be able to answer quite confidently. In ABAP, we are just blind. I even sometime break my software and found them out later.

I think it’d be good if I have one for ABAP so at least when somethings goes wrong, I, as ABAP developer, should know it as soon as possible before someone else does. I didn’t expect much at the beginning but just to execute some tests every time we make changes in ABAP i.e. continuous integration.

Who know, I eventually got both CI and CD in the pipeline for ABAP running. Not perfect, but good enough. Here is the pipeline in Jenkins for ABAP:

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Testing and Analysis

Comparing to our Java pipeline:

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Testing and Analysis

In this blog, I will guide how to setup the same CI pipeline for your ABAP backend.

Prerequisites


1. An ABAP system with ADT (ABAP in Eclipse) enabled and abapGit installed
2. A Jenkins server with Node.js and newman installed

My recommendation is to build a SAP NetWeaver AS ABAP and SAP BW 7.50 SP02 on ASE [Developer Edition] on the cloud either Azure or AWS via SAP CAL.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Testing and Analysis

For Jenkins, once you get the Developer Edition up and running, you also get a Windows 2012 server frontend instance as well. Download and install Jenkins on the server. Install all recommended plugins and you should be ready to roll.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Testing and Analysis

For Node.js, you can use Chocolatey to ease the installation. For newman, you can install via npm (comes with Node.js).

Using Git Repository for ABAP


Why do we use Git for ABAP? This is the question I usually get. Well, I didn’t want to use at the beginning but I want to deploy a mechanism where the Jenkins is triggered every time when ABAP code is changed.

I may insert a custom logic somewhere in ABAP to trigger Git when developer release their task which similar to when Java developer commit and push their code. But this is too complicated. I don’t want to write ABAP codes to automate ABAP codes.

Since there’s great tool like abapGit and I know Git can trigger Jenkins then why don’t we do them to ease our works.

Later, I found more benefits using Git for ABAP. One day, I was asked what changes over the past 2 weeks we are moving to production. I made lots of changes during those 2 weeks so I can’t remember all of them. I just go to Git and see all the logs of changes I made. I can even show exactly what changes I had made line by line.

Apart from change log, another benefit for developer is code backup. I sometime need to restore to the code I wrote and already deleted yesterday or last week. It usually a problem for me when I haven’t started using Git because, by nature, ABAP developers are not create new version that often. Using Git and apply practice ‘commit every day’ helps a lot.

Git also helps enforcing developer to modularize their objects in separated package. I used to see more than 3,000 objects in the same package then package is not used by its purpose at all.

Pushing Codes to Git


If you haven’t done so, create a Git repository and push your ABAP codes into it. In this tutorial, I’ll use my simple REST API repository as an example. Feel free to clone it to package the $REST_SIMPLE.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Testing and Analysis

Adding Jenkinsfile


Go to your Git repository and add Jenkinsfile (You don’t have to do this if you use my repository as I already did). Paste the following content and commit.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Testing and Analysis

You should see Jenkinsfile in your repository.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Testing and Analysis

Building Jenkins Pipeline


The good thing about PaaC (Pipeline as a Code) like groovy is you can maintain the whole pipeline in the code format that mean you can version-control it on Git as well. Coding means less configuration required and minimize clicking, typing, and waiting through the UI.

Creating a New Pipeline Job


In Jenkins, create a new Pipeline job.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Testing and Analysis

Set up Build Triggers to pull from Git every minute. Or you may setup web hook.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Testing and Analysis

Configure Pipeline by reading Jenkinsfile from your Git repository.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Testing and Analysis

Create a Credential


Go to Credentials and add a new one like below. This is the username and password you will let Jenkins to log on to ABAP system.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Testing and Analysis

Run


Go back to your job and click Build Now to start building. If everything is setup correctly, you should see the pipeline completed successfully like below.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Testing and Analysis

Continuous Delivery


Continuous Delivery is about keeping delivering value to customer. Features or changes that are done should be moved to QA/Staging as soon as possible so user can test and provide feedback.

You can append Jenkinsfile to perform additional stages to get your changes into QA environment. This will vary depending on process and system landscape in your company. How to write Jenkinsfile is another long blog so I won’t explain it here.

In my case, I’ve decided to build the tools to automate our current process. We are using SolMan to manage transport. Normally, when we want to move change to QA, we log on ChaRM BSP webpage and release the document from there. Our import job runs regularly to import changes into QA.

So I built an UI automation to automate this manual process. Wait for transport import. Then run another set of tests on QA. The tool I used is Robot Framework and Selenium. Of course, that can be another long blog.

However, in my case, there’s still a gap in this pipeline. Because ABAP developer can skip this quality pipeline and go back to their traditional steps. So I view this pipeline as an option to help developers and the team delivery faster with more quality. If we need to enforce the pipeline, then that would require a big change in the process and the way of work for many teams.

No comments:

Post a Comment