Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

Every serious software project needs automated continuous integration builds. Especially for cloud applications, this is not so difficult: the whole process from building via deployment to final testing can be automated easily. The usual tool for automating continuous integration builds is Jenkins.

In this blog, I describe how to set up a Jenkins running on the SAP HANA Cloud Platform that performs continuous integration builds for a cloud application. Of course I will use the famous "Hello World" as an example - this time in an SAP HANA Cloud edition. You find the sources of the "Hello World" project on GitHub. It is a slightly modified version of the "Hello World" example in the SAP HANA Cloud SDK.

You will learn how to create a Jenkins build job that fetches the sources from GitHub and builds them with Apache Maven. The maven build of the "Hello World" project creates, deploys and starts a "Hello World" application in a developer account on the SAP HANA Cloud Platform. This Maven build also executes an integration test against the running "Hello World" application and stops it afterwards.

What are the prerequisites?

You have to use two developer accounts on the SAP HANA Cloud Platform, one for Cloud Jenkins and one for "Hello World". A developer account is restricted to run only one application at one time. This is a good opportunity for doing pair programming, isn't it?

In short, you need Apache Maven 3.0.4 or newer, Git, two developer accounts on the SAP HANA Cloud Platform and the SAP HANA Cloud SDK 1.51.16. Unzip the SAP HANA Cloud SDK to a directory neo-sdk-javaweb-1.51.16. The SDK contains the neo command line tool that you need for deploying later.

If you want to dig a little deeper: You can find a very well and detailed description on how to setup your developer workspace and account in Jens Glander's SAP HANA Cloud Application Development Scenario End-to-End Tutorial.

By the way, I prefer to use a "Git Bash" as console and so I will stick to unix style in the command line examples listed below.

Jenkins In The Cloud

The original Jenkins distribution that can be downloaded from http://jenkins-ci.org/ doesn't run well on SAP HANA Cloud. It does work, but it doesn't survive restarts. Jenkins works with the file system but there is no persistent file system available in the developer accounts of the SAP HANA Cloud Platform. After an application restart, everything stored on the file system will be lost.


The Cloud Jenkins overcomes this limitation by storing the configuration in the document service of the SAP HANA Cloud Platform. Besides providing Jenkins in the cloud, this is also a good example of how other applications could cope with the absence of a persistent file system.

The necessary Jenkins plugin that integrates Jenkins with the SAP HANA Cloud Platform is implemented in the cloud-jenkins project. So the first step is to build the cloud-jenkins project to convert a standard Jenkins into a cloud enabled Jenkins.

First you clone the "sap/cloud-jenkins" project from Github. In a console you go to your workspace directory and enter


git clone https://github.com/SAP/cloud-jenkins cd cloud-jenkins











Then you build the Cloud-Jenkins project. with Maven. The project depends on artifacts which can be found in repo.jenkins-ci.org/public. You make sure that Maven can reach this repository e.g. by adding it to your Maven "settings.xml". Most likely this is located at "${user.home}/.m2/settings.xml". If you are behind a firewall you need to configure a proxy in the "settings.xml" file, too. If not you can skip the proxy entry.


<proxies>


  <proxy>


      <protocol>http</protocol>


      <host>proxy.somewhere.com</host>


      <port>8080</port>


      <username>proxyuser</username>


      <password>somepassword</password>


      <nonProxyHosts>localhost</nonProxyHosts>


  </proxy>


</proxies>



<repositories>


    <repository>


      <id>repo.jenkins-ci.org</id>


      <url>http://repo.jenkins-ci.org/public/</url>


  </repository>


</repositories>



<pluginRepositories>


    <pluginRepository>


      <id>repo.jenkins-ci.org</id>


      <url>http://repo.jenkins-ci.org/public/</url>


  </pluginRepository>


</pluginRepositories>











You let Maven create the file "cloud-jenkins-webarchive/target/ROOT.war" by simply calling


mvn clean install











The next step is to deploy the web archive to the developer account on the SAP HANA Cloud Platform. This is easily done with the neo command line tool. Remember: It is part of the SAP HANA Cloud SDK and located in its "tools" sub folder. If you are behind a proxy you have to set the following environment variables before you execute the neo command.


export http_proxy=http://<HTTP proxy hostname>:<HTTP proxy port>


export https_proxy=https://<HTTPS proxy hostname>:<HTTPS proxy port>


export no_proxy="localhost"











Let's bring Jenkins to the cloud. In a console you invoke


<path to neo tool>/neo.sh deploy --host hanatrial.ondemand.com --account <your developer account> --application jenkins --user <your user ID> --source cloud-jenkins-webarchive/target/ROOT.war --uri-encoding UTF-8











You have to configure the permissions for the Cloud Jenkins deployment. So you go to the SAP HANA Cloud Platform cockpit. I assume you have a totally new developer account and so you expect your 'jenkins' application to be listed together with the 'welcome' application. Both are in the status stopped.

On the "Authorizations" tab you enter user ID and click on "Show Roles". Your user has to be assigned to the "admin" role of the "jenkins" application.


You start the "jenkins" application on the "Applications" tab. The application status page also shows the URL of the application.

As a result, you get a running Jenkins instance. Click on the URL of the "jenkins" application, log in and have a look at the "Manage Jenkins" page.

Regard the cloud symbol. Your "jenkins" application has an additional plugin that provides the "Manage Jenkins Installation on Cloud" link.

With the "Manage Jenkins Installation on Cloud" UI you can
  • Upload files to Jenkins
    The provided zip archive is extracted to the home directory (~) of the user running the Jenkins instance. The JENKINS_HOME directory is in the ".jenkins" sub-directory. For example you can upload an archive with a file ".jenkins/jobs/<job name>/config.xml" to add a job with a configuration copied from a different Jenkins instance. You can even upload an archive with a ".m2/settings.xml" file to overwrite the global Maven settings.xml.
  • Delete files from Jenkins
    You can delete a file or a folder including its content. Again, the path must be relative to the home directory (~) of the user running the Jenkins instance.
  • Store the Jenkins configuration in the SAP HANA Cloud document service so that it survives a restart
    The selected files are stored in the SAP HANA Cloud document service. When the Jenkins application is restarted, the stored configuration is reloaded from the SAP HANA Cloud document service. You can specify which files are to store in the SAP HANA Cloud document service and you can use Ant style wildcards. Paths must be relative to the home directory (~) of the user running the Jenkins instance, e.g. ".jenkins/*.xml, .jenkins/jobs/*/config.xml, .jenkins/plugins/*.jpi, .m2/settings.xml".
    You can also define an optional exclude pattern. Files matching this exclude pattern will not be stored in the SAP HANA Cloud document service. If you want to exclude the SAP HANA Cloud Jenkins plugin you would specify ".jenkins/plugins/cloud-jenkins.jpi". In this case the version shipped with the Cloud Jenkins war file is used. Be aware that all files which have been stored last time and do not match the actual selection pattern anymore will implicitly be deleted from the document service with the new store action.
  • Restore the Jenkins configuration from the SAP HANA Cloud document service
    The result of this action is not a reset of the Cloud Jenkins file system to what one would get after an application restart. Instead it just brings back all content being stored in the document service and leaves the rest of the file system untouched - like e.g. new unsaved projects and the build history.
  • Download the Jenkins configuration
    The downloaded archive contains all the content that is stored in the document service - in your case the Jenkins configuration. This archive can for example be uploaded to a different Jenkins via 'Upload files to Jenkins'.

Setting Up A Continuous Integration Build Job

As next step, you add a new build job on your Jenkins instance. As stated above this job shall sync a project from gitHub and build it with Maven. The project itself is configured to use the neo tool for deploying the application war file to the SAP HANA Cloud Platform and test it. Don't hesitate to look at the "pom.xml" file and the code of Stephan Merker's Cloud Helloworld example to see how this can be achieved. This project is based on the "hello-world" example from the SAP HANA Cloud SDK.

Create a new free-style software project job with the name "cloud-hello-world". The project you want to build expects a set of environment variables. Be aware that you need the credentials from the second account now. Select "This build is parametrized" and add the following:

Parameter TypeParameter NameDefault ValueDescription
String ParameterSAP_CLOUD_ACCOUNT<to do>Your account on https://account.hanatrial.ondemand.com
String ParameterSAP_CLOUD_USERNAME<to do>A user with deploy permission in your account
Password ParameterSAP_CLOUD_PASSWORD<to do>The password of the given user
String ParameterPROXY_HOSTproxy-trial.od.sap.bizfrom Manage Jenkins -> System Information -> http.proxyHost
String ParameterPROXY_PORT8080from Manage Jenkins -> System Information -> http.proxyPort


Mark Git as "Source Code Management" and enter "https://github.com/stephanme/cloud-helloworld.git" as "Repository URL". "Branch to build" has to be set to "**". In the "Build" section you add a "Invoke top-level Maven targets" step. Select "Maven 3.0.5" as Maven version, let the goals be "clean verify -B -e -P cloud-integration-tests" and press the "Advanced" button. You have to mark "Use private Maven repository" and leave the rest of the parameters as they are.

After clicking the "Save" button at the bottom of the page the job is created. To view the configuration of this job on the Cloud Jenkins reference instance just go to https://jenkinsp1940131088trial.hanatrial.ondemand.com/job/cloud-hello-world/configure. Run the build job by clicking "Build With Parameters" and as you already specified all parameter's default values, leave them as they are and just press "Build".

The build should succeed, of course and the build log should end like



How do you assure that the new jobs are still available after an application restart when the file system is not persistent? The answer is very easy: By storing the configuration in the SAP HANA Cloud document service via "Manage Jenkins -> Manage Jenkins Installation on Cloud". Click the "Store" button in the "Store Jenkins configuration in SAP HANA Cloud document service" section and confirm the files to store on the next screen.

Let's see what happens after a restart if you stop and then start the Cloud Jenkins application. Go to the SAP HANA Cloud Platform Cockpit, stop the application "jenkins" and afterwards start it again.

After the restart all files that have not been persisted in the SAP HANA Cloud document service vanished. As a result the job "cloud-hello-world" is still there but looks like it did never run. The history and workspace of the job are lost.

Instead of manually triggering the build job you can poll for changes of your SCM project, install additional plugins and use all the other nice features that Jenkins provides. As you just saw you have to take care that all the files you need after an application restart were previously stored in the document service.

Here goes! Have fun with your CI Jenkins Server On SAP HANA Cloud.

Best regards, Stephan Weber

18 Comments