Thursday 30 November 2017

Listing repositories in CentOS Linux

In CentOS and Red Hat flavors of Linux, if we want to list all the configured repositories, we need to use the following command.

yum repolist

This will list information with columns like repo id, repo name, status.

Use the verbose mode with the -v switch for more detailed information.

yum -v repolist

For listing only enabled and/or disabled repositories, use the following syntax

yum repolist enabled

OR

yum repolist disabled

For listing all of the repositories (i.e enabled and disabled), use :

yum repolist all

Now, from the list of of all configured repositories, if we want to disable/enable a specific repository, use the following :

yum-config-manager --disable test-repo-name.repo

OR

yum-config-manager --enable test-repo-name.repo

Hope it helps guys. Ciao!

Execute Shell in Jenkins - Update Permissions Example

Hello guys. How's it going? In today's post, let us look into an example of how to execute a shell command in Jenkins.

For illustration, let us consider a Java based project which is under IBM Clearcase source control and built using Maven on a Linux machine. Now we want to execute a bash command to update the permissions of all pom.xml files (i.e Parent pom's and Child pom's).

Check a few sample commands for reference :

find $WORKSPACE/$CLEARCASE_VIEWNAME/PROJECT_SRC_CVOB/SRC -type f -name pom.xml -exec chmod 755 {} \;

find $WORKSPACE/$CLEARCASE_VIEWNAME/PROJECT_SRC_CVOB/SRC -type f -name pom.xml -exec chmod 444 {} \;

find $WORKSPACE/$CLEARCASE_VIEWNAME/PROJECT_SRC_CVOB/SRC -type f -name pom.xml -exec chmod 777 {} \;

Hope it helps. Ciao!

Tuesday 28 November 2017

Learn Deutsche - German nouns : Set 1

Guys, in the past few posts, we looked into a few random word sets covering most commonly used Deutsche verbs. In this post, let us look into a new word-list of proper nouns used in our daily lives. We will also mention the gender of these words i.e der (Masculine) /die (Feminine) /das (Neutral). This should aid you in remembering the same. In today's set let us look into the most common words for office supplies/stationary.


Set 1 (Stationary / Office Supplies) - 12 words :

Pencil : der Bleistift
Pen : der Kuli
Eraser : der Radiergummi
Ruler : das Lineal
Notebook : das Heft
Dictionary : das Wörterbuch
Glue Stick : der Kleibstift
Scissors : die Schere
Ink : die Tinte
Paper : das Papier
Stapler : der Hefter
Picture : das Bild

Thursday 23 November 2017

How to enforce specific JDK for a Maven build

As you maybe aware, the Maven enforcer plugin provides the option to enforce specific rules while building a project. For instance we could enforce a specific version of JDK to be used for a build.

For instance, let us enforce the usage of JDK 1.8.0. In that case, check the configuration of maven-enforcer-plugin in your main parent POM

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>enforce</id>
<goals>
<goal>enforce</goal>
</goals>
<phase>validate</phase>
</execution>
</executions>
<configuration>
<rules>
<requireJavaVersion>
                  <version>1.8.0</version>
                </requireJavaVersion>
</rules>
</configuration>
</plugin>

Note the <requireJavaVersion> tag used for the same. For more information, check the following link as well.

How to configure Jacoco plugin in Maven

Guys, for getting the unit test coverage report in SonarQube for code quality and analysis, let us look into how to use the Jacoco plugin for the same. In this post we'll see how to configure Maven with the Jacoco plugin. FYI Jacoco is a free code coverage tool for Java


In your main parent POM, let us enter the Sonar properties firstly, as follows :

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Sonar -->
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.jacoco.reportPath>${project.basedir}/target/jacoco.exec</sonar.jacoco.reportPath>
<sonar.language>java</sonar.language>
<drools.version>5.5.0.Final</drools.version> 
</properties> 

Now in the <pluginManagement> section, let us enter the configuration for the Jacoco plugin.

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.2.201409121644</version>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>

Hope it helps guys. Until next time, ciao!

Automate regular backups of SonarQube's DB using bash script

Guys, this post will be useful if you are using SonarQube for code analysis and quality control. In today's post we will look into how to automate taking regular backups of SonarQube's back-end database.


For illustration, we will use MySql DB to store SonarQube's metadata which includes analysis parameters like code smells, bugs, code coverage, unit test coverage etc. In this case we host Sonar on a linux machine, so we write a bash script to take regular backups of the MySql DB. Take a look at a simple sample script below :

#!/bin/bash
# script for taking database dump of sonar

user="root";
hostname="localhost";
db_name="sonar";
dateformat=`date +%d-%m-%y`;

mysqldump --defaults-extra-file="/usr/local/cron_scripts/.my.cnf" -u $user -h $hostname sonar | gzip > /usr/local/mysql_dumps/sonar_dump_$dateformat.sql.gz

chmod 755 /usr/local/mysql_dumps/sonar_dump_$dateformat.sql.gz

As you see, we have used mysqldump to take dump of the database, zip it, append it with the current date and store it at the said location.

Taking dumps of Sonar can be extremely useful for the purpose of importing and exporting of a Sonar instance from one machine to another without losing the analysis history.

Change default javadoc output directory in Maven

When using the Maven javadoc plugin for generating javadoc for your project, we also have the option of changing the default output directory. As you know, by default the javadoc gets created within the project-folder/target/apidocs directory.

So, when updating the location of javadoc's output directory, use the <reportOutputDirectory> tag. Consider the illustration below :

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
<reportOutputDirectory>E:\\Javadoc\${project.name}</reportOutputDirectory>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>

As you see in this case we have updated the javadoc output directory to a different drive itself i.e. E:\\Javadoc\${project.name}. Kindly check this link as well for additional reference.
Related Posts Plugin for WordPress, Blogger...
eXTReMe Tracker