Skip to Content
Technical Articles

Continuous Integration & Deployment on SAP Cloud Platform – Part 4

Extending the pipeline

After creating a CI/CD pipeline within Jenkins including the predefined steps from SAP’s Project Piper we will show how to extend the pipeline by including a Nexus repo as well as Sonaqube¬†for source code analysis. This are just examples on how to extend the pipeline.

Nexus Repository

Nexus Repository provides storage for build artefacts, the ones created by your pipelines as well as the ones you use, e.g. in Maven or NPM builds as a proxy. In our example we’ll use it to store the artifacts created from the build step in our pipeline.

Use nexus as build cache

The cx-server already includes a Nexus build in. It’s used as a cache for the build.

In order to use it , open your terminal and make sure that the cx-nexus docker container is running. The common pipeline environment will check if the cx-nexus is available and will use them as build cache.

External Nexus to store artefacts

To add an external nexus to our environment we need to download and run a nexus docker container. Next, we need to create new docker network to connect the Jenkins container to the nexus container. Open the terminal and run docker network create nexus. Next, we need to connect both container to this new network by running docker network connect nexus cx-jenkins-master and docker network connect nexus nexus.

Next, we switch to our Jenkins and go to “manage Jenkins” -> “Configure System”. Scroll down till you reach the “Sonatype Nexus” section. If there is no Sonatype Nexus configuration you may need to install the nexus plugin in Jenkins. Fill in the gaps for the nexus configuration like this:

The credentials for the nexus can be set inside the nexus interface. This can be accessed by default using http://localhost:8081.

Create a new step and add the following content:

nexusPublisher nexusInstanceId: 'localnexus', nexusRepositoryId: 'maven-releases', packages: [[$class: 'MavenPackage', mavenAssetList: [[classifier: '', extension: '', filePath: '/var/jenkins_home/workspace/Job-Name_Branch/Projectname.mtar']], mavenCoordinate: [artifactId: 'jenkins-mtar', groupId: 'org.jenkins-CF.main', packaging: '.mtar', version: '1.' + env.BUILD_NUMBER]]]

After this the pipeline will store the build artefact in the Nexus:

Sonaqube

The Sonaqube code scanner allows you the scan the project for coding issues as well as code guidelines in order to achive better code quality.

Add sonar Scanner

Now we want to add a sonar scanner to our project. As described in the previous step download, run and add the container to a docker network.

Open the interface of the scanner an create an account. Next set up a new project and an authentication token. This token needs to be stored in Jenkins credentials as a secret text.

Also open the configure system section and configure the SonarQube server:

Also install the sonar scanner plugin. Move up to manage Jenkins and open the global tool configuration. And scroll down to SonarQube scanner:

Now we can switch into our IDE and adjust our Jenkinsfile.

First, we need to create a new file in the root directory of our project named sonar-project.properties this file contains basic configurations:

sonar.projectKey= Name of sonar project
sonar.projectVersion=1.0
sonar.sourceEncoding=UTF-8

Add a new step to your Jenkinsfile and use the following content:

script {
    git "URL to git repository"
    def scannerHome = tool 'SonarCloud';
    withSonarQubeEnv('SonarCloud') {
        sh "${scannerHome}/bin/sonar-scanner"
    }
}

Results

After executing the extended pipleline you’ll be able to see the scan results on the Sonaqube page:

Summary

As you can see, the Jenkins pipeline is flexible and can be extended/adopted to your needs. That’s all for this blog series introducing different ways for continuous integration and delivery on SAP Cloud Platform.

Be the first to leave a comment
You must be Logged on to comment or reply to a post.