Integrating Ossum with Jenkins

October 8, 2019 Sara Spink

Teams that have adopted a Continuous Integration/Continuous Delivery (CI/CD) approach need integration with their entire workflow, from planning to deployment. Ossum lets teams rely on a single, comprehensive toolset for their development workflow, and integrating an existing CI service such as Jenkins is quick and easy. In this article, we'll demonstrate how easy it is to integrate an ossum workflow with your Jenkins CI automation.

Why Adopt Continuous Integration?

CI/CD is the modern DevOps process of fully automating the compilation, testing, and deployment of software projects. Properly implemented, CI will quickly let you know if a commit has broken something, stop the deployment process, and allow the developer to rapidly track down the problem while still working on the code. CI allows for the rapid iteration of small changes with reduced risk of anything breaking, and fast recovery if something does.

Once you have full trust in your CI process, automating continuous deployment avoids simple mistakes like copying the wrong directory or missing a critical piece if it is fully manual. And with CD, your team will not be dependent on the one person who knows how to do the deployment.

With CD, you can also create approval workflows so that not only will changes not break the build/test, but each change will also be reviewed at both a code and feature level. For example, after the CI process runs, and before actual deployment, the team lead may review the code, and a product manager may review the change and make sure it implements the intent of the original feature request.

Ossum has you covered for all aspects of the software development cycle. It allows you to plan and track both new features and issues while tying it all to an integrated Git repository, workflow engine, and DevOps CI/CD process.

CI/CD Integration with Jenkins

Integration with your favorite CI/CD tools such as Jenkins, TeamCity, and Bamboo can be accomplished in just a few steps. Each time commits are pushed to the Git repository, builds will be initiated on your Jenkins server or other CI/CD server. The build status will be easily tracked on the story cards in ossum and in your commit history.

The main requirement for integrating Jenkins (https://jenkins.io/) with ossum is that the Jenkins server is accessible from the internet or via an encrypted tunnel/VPN such as ngrok (https://ngrok.com/). Allowing ossum to access the Jenkins server allows ossum to trigger builds and get status and messages from the build.

The steps to integrate ossum with your Jenkins engine include:

  1. Configure Jenkins with variables and credentials that will be passed by the Git repository when a job is kicked off.
  2. Create a Jenkins build job via the Jenkins web UI or a jenkinsfile in the root of your Git repository.
  3. Configure the ossum Git repository to call Jenkins when appropriate.

Start by adding ossum credentials to Jenkins:

Now, create a Jenkins job. Note that both Freestyle and Pipeline jobs are supported. With Freestyle, you will set up the job steps in the Jenkins web user interface. With a Pipeline job, all Jenkins commands will be stored in a file named “JenkinsFile” at the root of your repository.

Once you’ve clicked the “OK” button, you can configure the project within Jenkins. Two requirements are:

  • Configuring job parameters
  • Setting up the Jenkins Git client to point to your ossum repository.

Here is a list of parameters that ossum will send to Jenkins:

Name

Type

Default (recommended)

Description

ossum_merge_request

Boolean

false

True if a merge request that must be verified; false if a normal commit.

ossum_revision

String

*/master

Git sha of the change

ossum_refspec

String

refs/heads/master

Git refspec of the change

pssum_before_revision

String

 

Previous git sha

ossum_url

String

 

URL to view the commit or merge request in ossum.

You can add parameters in Jenkins by clicking on the “This project is parameterized” option and adding the parameters from the table:

The first two parameters have been configured below. After adding your parameters, don’t forget to click on “Save” before proceeding!

For ossum to work with the Jenkins API, at least one parameter must be created (even if it is not used) so that the ossum plugin will work properly. Others are optional, depending on your requirements.

Git and Jenkins

The next thing to do is install and configure the Jenkins Git client. In the Source Code Management section of the Jenkins job, click on “Git.” Copy and paste in the “Clone URL” of your repository, which can be found in the “Download” section of your ossum repository.

Clicking on “Advanced” will allow you to specify the $ossum_refspec parameter previously defined. Likewise, “Branches to build” is supplied by the $ossum_revision parameter. (Note the leading “$” to specify a parameter instead of a value.)

An alternative approach is to supply a “Jenkinsfile” stored in the root of your Git repository and configure a Jenkins Pipeline project to execute it. The configuration is very similar to the previous example, except that the parameters will be specified in the “Jenkinsfile” in source control.

 

 

Here's an example of a “Jenkinsfile”:

pipeline {

  agent any

  options {

      buildDiscarder(logRotator(numToKeepStr: '10'))

      skipDefaultCheckout()

      timestamps()

      timeout(time: 20, unit: 'MINUTES')

      durabilityHint 'PERFORMANCE_OPTIMIZED'

  }

  parameters {

      booleanParam(name: 'ossum_merge_request', defaultValue: false, description: 'Change is a Merge Request')

      string(name: 'ossum_revision', defaultValue: '*/master', description: 'Revision to build', trim: true)

      string(name: 'ossum_refspec', defaultValue: 'refs/heads/master', description: 'Refspec', trim: true)

      string(name: 'ossum_before_revision', description: 'Before revision', trim: true)

      string(name: 'ossum_url', description: 'Browser URL', trim: true)

  }

  stages {

    stage('Build') {

      steps {

          echo 'Running the build step'

      }

    }

    stage('Test') {

      steps {

          echo 'Running the test step'

      }

    }

    stage('Publish') {

      when { not { expression { return params.ossum_merge_request } } }

      steps {

          echo 'Running the publish step'

      }

    }

  }

}

Note that you can call up the Jenkins “Linter” via the command line or HTTP post. For more information, visit: https://jenkins.io/doc/book/pipeline/development/. There is a plugin for Visual Studio Code as well.

Configure Ossum

You can set up Jenkins and other services in the “DevOps” area of your ossum account. From your project, click on the gear near the right side of the upper menu bar, then ”Accounts” on the left menu area. Select the account where you want to set up DevOps.

Setup requires configuring the Jenkins job parameters and Git client plugin parameters. Full instructions for this process are simple and available in the documentation under Setup Jenkins Classic Build Job.

To complete setup, you'll also need the Git clone URL for the repository, which you can obtain from the ossum dashboard.  Git clone URL for the repository, which you can obtain from the Ossum dashboard[1] .

Separate Jenkins jobs can be specified for normal commit and merge requests.

Conclusion

This article has provided a quick review of the steps required for setting up communication between Jenkins and ossum. You can find additional information in both the ossum and Jenkins documentation.

Try a “Totally Ossum” subscription free for 30 days right now.

Previous Article
Best Practices for Using Git with Ossum
Best Practices for Using Git with Ossum

Take git to the next level. Use ossum to track branches in graph view, create merge requests, get team feed...

Next Article
Setting Up a Software Development Environment
Setting Up a Software Development Environment

Before you begin working on a new project with your team, you need to set up a robust and reliable developm...

One smart tool to plan, code, and launch software.

Try ossum