Component XML Repository Scripts

There are three example scripts for adding the component XML to a repository and performing code quality analysis on the integrations. The three are independent of each other but can also be used together to perform required tasks.

  1. component_xml_git.py - This script will add the component XML from the release file to a repository. The script will loop through the processes that are being deployed and add all component XMLs that are associated with a packaged component into a directory in the repository.

  2. component_xml_code_quality.py - This script will perform a code quality check based on the rules found within boomi_cicd/templates/sonarqube/BoomiSonarRules.xml. Once the code quality analytsis is complete, the results are commited to the Boomi Components XML repository. component_xml_git.py is required to be run before this script.

  3. component_xml_sonarqube.py - This script will perform a code quality check within SonarQube. component_xml_git.py is required to be run before this script. Once the component_xml_git.py is ran, this script will load the XML files into SonarQube to perform a code analysis.

component_xml_git.py

The component_xml_git.py script will loop through the packaged components that are being deployed and add all component XMLs that are associated with the packaged component into a folder in the repository. The folder structure is as follows:

boomi_components/<package_component_name>/<component_name>.xml
Table 1. Required Environment Variables for component_xml_git.py

Environment Variable

Values

BOOMI_COMPONENT_GIT_URL

URL for the Boomi Components Repo. The URL includes a private access token.

BOOMI_COMPONENT_REPO_NAME

The name of the repo directory created during the build. Boomi_Components is the default. Optional.

BOOMI_RELEASE_FILE

Release file that contains components to deploy.

component_xml_code_quality.py

The component_xml_code_quallity.py script will take the XMLs from the Boomi_Components repository and run a code quality check on them. The check uses rules found within boomi_cicd/templates/sonarqube/BoomiSonarRules.xml. The XML structure of the BoomiSonarRules are based on the backup profile within SonarQube. Other files can be used by defining the BOOMI_SONAR_RULES_FILE environment variable.

Once the check is complete, the results are written to the boomi_components repo and commited to the main repo. The results of the code qualilty check is written to report.md within the root directory of the repository and is formatted in markdown.

Table 2. Required Environment Variables for component_xml_code_quality.py

Environment Variable

Values

BOOMI_COMPONENT_REPO_NAME

The name of the repo directory created during the build. Boomi_Components is the default. Optional.

BOOMI_SONAR_RULES_FILE

The file that contains the code quality rules. The file is `boomi_cicd/templates/sonarqube/BoomiSonarRules.xml

component_xml_sonarqube.py

SonarQube is a tool used to perform code quality checks. It is often used with code. For Boomi, the XPath feature within SonarQube will be used to perform code quality checks on the Boomi Component XML. XPath is a query language for selecting nodes from an XML document.

First create a new Project and a token for the project. The project can be created under Administration -> Project -> Management. The token can be created for a user by going to My Account -> Security -> Tokens. The token will be used in the script to authenticate with SonarQube.

Once the project has been created, the XPath rules need to be added to SonarQube. To add rules to SonarQube go to Rules and Search for Track breaches of an XPath rule. Click on it and then click on “Create”. Add the information that is found within the boomi_cicd/templates/sonarqube/BoomiSonarRules.xml file. Each rule will need to be added manually to SonarQube.

../_images/component-xml-sonarqube-create-rule.png

Figure 1. Create new rule in SonarQube.

Once complete, the rule will show up under Customer Rules within Track breaches of an XPath rule.

../_images/component-xml-sonarqube-rule.png

Figure 2. New rule that has beeen created in SonarQube.

Figure 3 shows what SonarQube looks like once all Boomi SonarQube rules have been added to the custom XPath rules.

../_images/component-xml-sonarqube-rules.png

Figure 3. Boomi Rules in SonarQube

Once the rules have been added, the Quality Profile backup can be restored. Go to Quality Profiles and click on Restore. Select a locally downloaded version of BoomiSonarRules.xml file and click on Restore. This will add all the newly created rules to the profile. The file does not create rules, but it does add existing rules to the profile.

../_images/component-xml-sonarqube-restore.png

Figure 4. Restore Quality Profile in SonarQube

../_images/component-xml-sonarqube-import.png

Figure 5. The Boomi Profile will be visable after the Quality Profile has been restored.

The new Quality Profile will need to be added to the new project. Go to Project -> new project -> Administration -> Quality Profiles. Next to XML, select Boomi as the Quality Profile. This will add the Boomi rules to the project.

../_images/component-xml-sonarqube-project-qp.png

Figure 6. The Boomi Profile added to the Project.

Finally, the following is the example python script for executing SonarQube. The script will download SonarScanner, which is a tool used to send the code (Component XML from the component_xml_git.py script) to SonarQube for analysis. Once complete, the analystic can be seen in SonarQube.

 1import os
 2
 3import boomi_cicd
 4from boomi_cicd import logger
 5
 6
 7sonarqube_dir = boomi_cicd.install_sonarqube()
 8
 9base_folder = '"' + os.path.join(os.getcwd(), boomi_cicd.COMPONENT_REPO_NAME) + '"'
10logger.info(f"Boomi Component Repo Directory: {base_folder}")
11logger.info(f"Sonar Host URL: {boomi_cicd.SONARQUBE_HOST_URL}")
12
13os.system(
14    rf"{sonarqube_dir}\bin\sonar-scanner.bat"
15    rf" -Dsonar.projectKey={boomi_cicd.SONARQUBE_PROJECT_KEY}"
16    rf" -Dsonar.projectBaseDir={base_folder}"
17    rf" -Dsonar.sources={base_folder}"
18    rf" -Dsonar.host.url={boomi_cicd.SONARQUBE_HOST_URL}"
19    rf" -Dsonar.login={boomi_cicd.SONARQUBE_TOKEN}"
20)

To run the script above, the following environment variables need to be set. The table below shows the required environment variables.

Table 3. Required Environment Variables for SonarQube

Environment Variable

Values

BOOMI_SONARQUBE_HOST_URL

URL for Sonarqube. i.e. https://domain.com:9000

BOOMI_SONARQUBE_PROJECT_KEY

The key for the newly created project

BOOMI_SONARQUBE_TOKEN

The user token

When the SonarQube script runs, if there are any XMLs that have bugs, then an error notification will be shown.

../_images/component-xml-sonarqube-bug.png

Figure 7. SonarQube Bug Notification

Each process will be a folder under Project -> Code. The folder will be named after the process. The folder will contain the Component XML.

../_images/component-xml-sonarqube-code.png

Figure 8. SonarQube Bug Notification