Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to integrate Jira plugins with Bitbucket, SonarCube, Jacoco and Bitbucket Pipelines

The aim of the article is to make a short guide on how to setup a simple Jira plugin development process using SonarCube, Jacoco , Bitbucket and Bitbucket pipelines. All of the mentioned tools are free of charge. Bitbucket pipeline offers you 50 free minutes per month to run your pipeline.
A few words on each tool.
SonarCube is a tool for code quality inspection. It can detect bugs, code smells and security vulnerabilities in your code.
Jacoco is a code coverage tool, which lets you measure how much of your code covered by unit tests.
Bitbucket is a web-based hosting service, which is  used for managing source code.
Bitbcket pipeline is a continuous integration tool.
The tools above will help you to develop a higher quality software.
Ok. Let's move to the guide section.
1. Create Bitbucket account on https://bitbucket.org/
2. Setup SonarCube.
2.1. Create a SonarCube account on https://sonarcloud.io/. Use your bitbucket account to authenticate in SonarCube.
2.2. Create a new organization called tutorial in https://sonarcloud.io/account/organizations
2.3. Generate a new security token in https://sonarcloud.io/account/security/
3. Install Atlassian SDK and create your first servlet Jira plugin.
I will make a short list of what should be done. You can find a more detailed explanation here:
https://developer.atlassian.com/server/framework/atlassian-sdk/set-up-the-atlassian-plugin-sdk-and-build-a-project/
https://developer.atlassian.com/server/jira/platform/creating-a-jira-issue-crud-servlet-and-issue-search/
3.1. Download Atlassian SDK.
3.2. Create a folder for storing your Jira plugins and execute the following command within the folder:
atlas-create-jira-plugin
Enter com.atlassian.tutorial for the groupId and ciprocess for the artifactId. Then press several times “Enter” and type Y when you are asked if you want to create the plugin.
3.3. Go down to the ciprocess folder (cd ciprocess) and execute the following command:
atlas-create-jira-plugin-module
When you are asked to choose a number you should choose 21. Number 21 means that the Servlet module will be created for you plugin. When you are asked questions about the servlet class name and package press enter. When you are asked “Show advanced setup” press N. When you are asked “Add Another Plugin Module” press N.
3.4 Run the plugin with the following command
atlas-run
After Jira started you can go to the following url in your browser:
http://localhost:2990/jira/plugins/servlet/myservlet
And you will see the “Hello World” message.
4. Connect Jacoco.
4.1. Add the following lines into the <build><plugins> section of the pom.xml file:
<plugin>
   <groupId>org.jacoco</groupId>
   <artifactId>jacoco-maven-plugin</artifactId>
   <version>0.7.9</version>
   <configuration>
      <destFile>${sonar.jacoco.reportPaths}</destFile>
      <append>true</append>
   </configuration>
   <executions>
      <execution>
        <id>agent</id>
        <goals>
          <goal>prepare-agent</goal>
        </goals>
      </execution>
        </executions>
 </plugin>
4.2. Add the following lines into <properties> section of the pom.xml file:
       <sonar.projectKey>tutorial.servlet</sonar.projectKey>
        <sonar.host.url>https://sonarcloud.io/</sonar.host.url>
        <sonar.login>240cb1aaf7aa6b5f08d7dda7e3a4a24c2677cn62</sonar.login>
        <sonar.organization>tutorial</sonar.organization>
        <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
        <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
        <sonar.jacoco.reportPaths>${project.basedir}/target/jacoco.exec</sonar.jacoco.reportPaths>
        <sonar.language>java</sonar.language>
Change sonar.login variable with the security token which you received in 2.3.
4.3. Create .gitignore file in the plugin directory with the following content
# Compiled class file
*.class
*.iml

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear
*.zip
*.tar.gz
*.rar


# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# User-specific stuff:
.idea/**/workspace.xml
.idea/**/vcs.xml
.idea/**/cint.iml
.idea/**/tasks.xml
.idea/dictionaries
.idea/
target/

# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml

# Gradle:
.idea/**/gradle.xml
.idea/**/libraries

# CMake
cmake-build-debug/

# Mongo Explorer plugin:
.idea/**/mongoSettings.xml

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

5. Put the source code to a bitbucket repository.
5.1. Sign in to your Bitbucket account
https://bitbucket.org/
5.2. Create a new repository with GIT version control and name it “ciprocess”.
5.3. Install on your computer GIT client.
5.4. Open terminal, go to your plugin folder and initialize a git repo with the following command:
git init
5.5. Add all files to the local repo by executing
git add *
git commit -m “initial commit”
5.4. Push your source code to the repo in Bitbucket. On the overview page of your created repository in bitbucket.org you will see instructions on how to put your source code into your repository. In my case instructions look like this
Step 1: Switch to your repository's directory
cd /path/to/your/repo
Step 2: Connect your existing repository to Bitbucket
git remote add origin https://alex1mmm@bitbucket.org/alex1mmm/ciprocess.git
git push -u origin master
Follow the instructions, which you can see in the overview page of your bitbucket repository.
6. Create bitbucket pipeline.
6.1. Go to your repository in Bitbucket.org and choose Pipelines menu.
6.2. Create pipeline for Java language. bitbucket-pipelines.yml should look like this:


image: translucent/atlassian-plugin-sdk:latest
pipelines:
  default:
    - step:
        script: # Modify the commands below to build your repository.
          - atlas-mvn -X clean package sonar:sonar # -B batch mode makes Maven less verbose


You can read more about creating bitbucket pipeline here:
https://confluence.atlassian.com/bitbucket/get-started-with-bitbucket-pipelines-792298921.html
7. Upon new pushes to the repository the pipeline will build your module and create the build report in SonarCube.
You can see the build report here:
https://sonarcloud.io/organizations/tutorial/projects

If you need the source code of the plugin you can get it here:
https://bitbucket.org/alex1mmm/ciprocess/src

TAGS
AUG Leaders

Atlassian Community Events