Skip to content

Commit

Permalink
Added role for installing 3rd party SonarQube plugins (#355)
Browse files Browse the repository at this point in the history
* Added role for installing 3rd party SonarQube plugins

* Improve readability and simplify
  • Loading branch information
InfoSec812 authored and tylerauerbeck committed Apr 11, 2019
1 parent 8875bb0 commit f00f7a1
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
23 changes: 23 additions & 0 deletions roles/add-sonar-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Overview

This role uses the OpenShift command-line tool to upload a JAR based SonarQube plugin into a running SonarQube instance, then restarts that running SonarQube instance so that the plugin gets loaded.

# Usage

```yaml
- name: Install C++ Community Plugin For SonarQube
hosts: ocp-sonarqube

roles:
- add-sonar-plugin
vars:
plugin_url: https://github.com/SonarOpenCommunity/sonar-cxx/releases/download/cxx-1.2.2/sonar-cxx-plugin-1.2.2.1653.jar
install_location: /opt/sonarqube/extensions/plugins
namespace: labs-ci-cd
pod_prefix: sonarqube
```
# Testing
* Deploy a [Labs CI/CD environment](https://github.com/rht-labs/labs-ci-cd)
* Apply the role using the test playbook: `ansible-playbook -i inventory test.yml
* Verify deployment after SonarQube restarts
29 changes: 29 additions & 0 deletions roles/add-sonar-plugin/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---

- name: Get JAR name
set_fact:
jar_name: "{{ plugin_url.split('/')[-1] }}"

- name: Download the SonarQube plugin
get_url:
url: "{{ plugin_url }}"
dest: "/tmp/{{ jar_name }}"
mode: 0440

## The Jinja2 template and the Go template in the following task conflict,
## so the weird double-curly-braces surrounded by double-curly-braces is required.
- name: Find sonarqube pod
command: >-
oc get pods --namespace={{ namespace }} -l="app==sonarqube"
-o jsonpath="{.items[0].metadata.name}"
register: pod_name_lines

- name: Extract pod name
set_fact:
pod_name: "{{ pod_name_lines.stdout }}"

- name: Copy plugin to SonarQube pod
command: "oc cp /tmp/{{ jar_name }} {{ namespace }}/{{ pod_name }}:{{ install_location }}/{{ jar_name }}"

- name: Redeploy SonarQube
command: "oc rollout latest --namespace={{ namespace }} {{ pod_prefix }}"
2 changes: 2 additions & 0 deletions roles/add-sonar-plugin/tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[ocp-sonarqube]
localhost ansible_connection=local
1 change: 1 addition & 0 deletions roles/add-sonar-plugin/tests/roles
10 changes: 10 additions & 0 deletions roles/add-sonar-plugin/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- name: Install C++ Community Plugin For SonarQube
hosts: ocp-sonarqube

roles:
- role: add-sonar-plugin
vars:
plugin_url: https://github.com/SonarOpenCommunity/sonar-cxx/releases/download/cxx-1.2.2/sonar-cxx-plugin-1.2.2.1653.jar
install_location: /opt/sonarqube/extensions/plugins
namespace: deven-role-test
pod_prefix: sonarqube

0 comments on commit f00f7a1

Please sign in to comment.