Tuesday 19 December 2017

How to change Timezone in Windows from Command Line

Guys, today let us learn how to change and/or update the Timezone on Windows machines without using the GUI i.e from the command line. On most flavors of Windows, the timezone utility (tzutil.exe) lies at C:\Windows\System32 location. 

Note : Updating timezone requires a user to have administrator rights. Make sure you have it.

So now, open the command line as administrator. Open the tzutil.exe from C:\Windows\System32 location. Let us look into a few illustrations on its usage.
  • To list current time zone :
C:\Windows\System32>tzutil.exe /g
Eastern Standard Time

  • To display the list of all available time zones :
C:\Windows\System32>tzutil.exe /l

(UTC+08:00) Irkutsk
North Asia East Standard Time

(UTC+08:00) Kuala Lumpur, Singapore
Singapore Standard Time

(UTC+08:00) Perth
W. Australia Standard Time

(UTC+08:00) Taipei
Taipei Standard Time

(UTC+08:00) Ulaanbaatar
Ulaanbaatar Standard Time

(UTC+08:30) Pyongyang
North Korea Standard Time

(UTC+08:45) Eucla
Aus Central W. Standard Time

(UTC+09:00) Chita
Transbaikal Standard Time

(UTC+09:00) Osaka, Sapporo, Tokyo
Tokyo Standard Time

(UTC+09:00) Seoul
Korea Standard Time

  • To update/set the time zone to a different time zone
C:\Windows\System32>tzutil.exe /s "Cen. Australia Standard Time"

So as you see there are basically only 3 switches to use /g /l and /s

Friday 1 December 2017

Learn Deutsche - German nouns : Set 2

Guys in today's post we will look into another new fresh list of Deutsche words. Let's get started. Today's theme is Colors (die farben).


Set 2 (Colors / die farben - 11 words) :

Red : rot
Blue : blau
Yellow : gelb
Green : grün
Brown : braun
Black : schwarz
White : weiß
Gray : grau
Violet : violett
Purple : lila
Pink : rosa

Thursday 30 November 2017

How to check system information on CentOS Linux from CLI

To check the system information of CentOS Linux from command line interface, the following commands will come in handy.

cat /proc/cpuinfo

processor       : 1
vendor_id       : GenuineIntel
cpu family      : 6
model           : 45
model name      : Intel(R) Xeon(R) CPU E5-4620 0 @ 2.20GHz
stepping        : 2
microcode       : 0x710
cpu MHz         : 2200.000
cache size      : 16384 KB
physical id     : 2
siblings        : 1
core id         : 0
cpu cores       : 1
apicid          : 2
initial apicid  : 2
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 popcnt aes xsave avx hypervisor lahf_lm ida arat pln pts dtherm
bogomips        : 4400.00
clflush size    : 64
cache_alignment : 64
address sizes   : 40 bits physical, 48 bits virtual
power management:

To check the memory details use the following :

vmstat -s

 3883788 K total memory
      3758516 K used memory
      2232252 K active memory
      1263620 K inactive memory
       125272 K free memory
            0 K buffer memory
       259872 K swap cache
      8191996 K total swap
      3114568 K used swap
      5077428 K free swap
    411521845 non-nice user cpu ticks
        23449 nice user cpu ticks
    116773236 system cpu ticks
   5900085167 idle cpu ticks
      1174004 IO-wait cpu ticks
         1058 IRQ cpu ticks
      7376135 softirq cpu ticks
            0 stolen cpu ticks
    234643114 pages paged in
    380977726 pages paged out
      3875967 pages swapped in
      4295358 pages swapped out
    948364036 interrupts
   1524453860 CPU context switches
   1479654445 boot time
    130969946 forks

You could also use an alternative command :

cat /proc/meminfo

MemTotal:        3883788 kB
MemFree:          119860 kB
MemAvailable:      89684 kB
Buffers:               0 kB
Cached:            64528 kB
SwapCached:       455596 kB
Active:          2526176 kB
Inactive:         993336 kB
Active(anon):    2503132 kB
Inactive(anon):   954552 kB
Active(file):      23044 kB
Inactive(file):    38784 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       8191996 kB
SwapFree:        4795948 kB
Dirty:                96 kB
Writeback:             0 kB

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.

Tuesday 31 October 2017

How to skip tests for specific module in a Maven build

In a Maven build of a multi module project, sometimes we may want to skip tests for only a specific module. For illustration, let's consider a multi module project with 10 modules and we want to skip tests only for 1 or 2 modules.

In such a scenario, enter the following in that module's pom whose tests we want to skip. We simply set the skipTests tag to true in the maven surefire plugin configuration.

<build>
        <plugins>
            <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
        </plugins>
    </build>

Until next time, Ciao.

Monday 30 October 2017

Learn Deutsche - German verbs : Set 6

Hello folks. Presenting another fresh list of random Deutsche verbs from the word bank.


Set 6
bleiben : to stay
glauben : to believe
duschen : to shower
vergessen : to forget
küssen : to kiss
warten : to wait
backen : to bake
kochen : to cook
waschen : to wash
anrufen : to call

Friday 27 October 2017

Learn Deutsche - German verbs : Set 5

Hello folks. Presenting the latest batch of Deutsche verbs wordlist.


Set 5
helfen : to help
kaufen : to buy
probieren : to try
bringen : to bring
verlieren : to lose
gewinnen : to win
fliegen : to fly
halten : to stop
lernen : to learn
tragen : to carry

Learn Deutsche - German verbs : Set 4

Hello guys. Let's look into another fresh batch of 10 random German verbs.


Set 4
kosten : to cost
trinken : to drink
shcreiben : to write
nehmen : to take
lieben : to love
reisen : to travel
singen : to sing
antworten : to answer
essen : to eat
schlafen : to sleep

Tuesday 24 October 2017

Learn Deutsche - German verbs : Set 3

Hello fellas! Hows it going? Well today we see a new word list with a fresh set of 10 new German verbs. Here we go...



Set 3
lesen : to read
mögen : to like
leben : to live
brauchen : to need
sitzen : to sit
haben : to have
fahren : drive, ride
beginnen : to begin
verstehen : to understand
wohnen : to live

Monday 23 October 2017

Learn Deutsche - German verbs : Set 2

In today's post let us look into another fresh batch of German words.



Set 2
suchen : to search
versuchen : to try
nehmen : to take
treffen : to meet
betreffen : to touch
anfangen : to begin
machen : to make
laufen : to run
sprechen : to speak
denken : to think

Learn Deutsche - German verbs : Set 1

Folks, from today onwards, am also starting a new series of posts specifically dedicated to the German vocabulary. The objective would be to make it easier to memorize German words with their equivalent English meanings, thereby enriching your German vocab. Each time, we will take only small batches of 10 random words and/or verbs to enhance and ease the memorization process.



In today's beginner level list let us check 10 random verbs which would be useful in our day-to-day conversation.

fragen : to ask
finden : to find
sehen : to see
arbeiten : to work
studieren : to study
spielen : to play
gehen : to go
wissen : to know
kommen : to come
sagen : to say

In next post, we will look into another fresh batch of word list with 10 new verbs and/or words. Until then, happy learning! Tschüss!

How to chain jobs in Jenkins using Parameterized trigger plugin

In Jenkins, sometimes we may need to trigger multiple jobs in a particular sequence, each performing some unique task. For instance let us consider a scenario, where we have one parent job to perform a maven build of a Java based project. We also have 2 separate child jobs for packaging - let's say one creates a Windows installer and the 2nd one which creates a Linux installer. Now, we want to automatically trigger the packaging jobs immediately after the build is finished. The Parameterized Trigger plugin helps us exactly to achieve the same. Using this, we can chain multiple jobs and pass parameters across them.

Let us consider the above scenario in some more detail.

Firstly, make sure the Parameterized Trigger plugin is installed in Jenkins.


Now, as said above I have one parent job which essentially performs a maven build of a Java based project. Once the build is finished, I want to trigger 2 child jobs - one which creates a Windows package and the other which creates a Linux package. In our case, we have the version 2.31 installed. Latest versions are available periodically.

Now, lets configure the chaining of packaging child job within the parent job i.e Maven build job. While doing so, I want to a bunch of pre-defined parameters across the build. For eg: I want to pass the build version and the location of Clearcase build view. The parameters could be either a constant variable or an environment variable.

Make sure to tick the option "This build is parameterized" and add a few parameters as desired.

Now add a new build step "Trigger/call builds on other projects" from the list.


Now all you have to do is mention the child build that you want to fire and the list of specific pre-defined parameters that you want to pass to it. Check the screenshot below for illustration.


Here we are passing 2 parameters - version and path_loc. Kindly note the syntax. Note that these 2 parameters need to be defined in both the parent and child jobs. In case you do not want to pass all the current build parameters instead of specific ones, simple choose the "Current build parameters" from the "Add Parameter dropdown list."


Alternatively, you could also pass the parameters from a specific properties file as well by specifying its location.

Ciao guys. Drop in your comments for any suggestions, questions or queries please. Grazie!

Wednesday 18 October 2017

How to open specific port in firewall in CentOS Linux

Guys, if your organization is behind a firewall, the networking team usually takes care that most unused ports are blocked, unless absolutely necessary. In some cases, you may want to add an exception to the firewall rules though, to open up a specific port to allow incoming and outgoing network traffic.

In today's example, we may want to open up a port 8080 to allow TCP connections for instance. Note that these commands are specifically for the CentOS flavor of Linux. Other flavors of Linux may have different command syntax. Please check accordingly.

Firstly view the existing firewall rules using the following command

firewall-cmd --list-all

Output (Old rules):

public (default, active)
  interfaces: en0
  sources:
  services: dhcpv6-client ssh
  ports: 9005/tcp
  masquerade: no
  forward-ports:
  icmp-blocks:
  rich rules:

As you see from the existing rules, it seems that port 9005 is open. Now let us add the port 8080 to the firewall rules using the below command. If the command is executed fine, it will display "success". Make sure to reload firewall configuration to bring the new rules into effect.

firewall-cmd --zone=public --add-port=8080/tcp --permanent
success

firewall-cmd --reload
success

In order to view the double check the firewall rules, again use the --list-all command.

firewall-cmd --list-all

Output ( Updated rules):

public (default, active)
  interfaces: en0
  sources:
  services: dhcpv6-client ssh
  ports: 8080/tcp 9005/tcp
  masquerade: no
  forward-ports:
  icmp-blocks:
  rich rules:

As you see the port 8080 has been added to the list i.e it has been opened up.

Tuesday 10 October 2017

How to automate Jenkins config backup

In today's post on Jenkins, let us learn how to take regular backups of our Jenkins environment configuration. There are a bunch of plugins out there which can help take thin and/or thick backups. But in our post we learn to take backups using a custom batch script.

We write a simple batch file which recursively takes backup of all Jenkins jobs and saves them in the destination directory. Later we set up a Windows scheduler job to execute this batch file daily.

rem IroncladZone
echo OFF

set today=%DATE:~7,2%%DATE:~4,2%%DATE:~10,4%
set url=http://17.16.18.14:8080/jenkins/
set dest_dir=C:\Jenkins_Jobs_backup\

cd /d "C:\Program Files (x86)\Jenkins\jobs"

FOR /D %%i IN (*) DO (

echo "Backing up %%i.xml"

"C:\Program Files\Java\jdk1.8.0_45\bin\java" -jar jenkins-cli.jar -s %url% get-job "%%i" > "%dest_dir%/%%i_%today%.xml"

echo "Successfully backup %%i.xml"

)

Note for taking backups, we use Jenkins' command line utility i.e jenkins-cli.jar. With this we save the Jenkins job configuration .xml file at the destination folder. Note that we append this .xml file name with today's date time-stamp so that we could easily identify it later.

Now all we have to do is set a Windows task scheduler job which runs this batch file to take backups at say 12:00 noon daily.


Hope it helps folks. Ciao!

LDAP authentication for SonarQube 5.6

Guys, if your project uses SonarQube for analyzing and improving the code quality, this is the post you should be interested in. In this post, we look into how to configure the organization-specific LDAP settings for SonarQube version 5.6

First of all, before we proceed, in order to enable LDAP authentication in SonarQube, you will have to install the LDAP plugin from the update center. In this illustration, we have the LDAP plugin version 1.4 installed. Newer versions of the plugin will be available periodically.



Now, navigate through your SonarQube installation directory => conf folder to find the sonar.properties file.

In this file, you'll able to configure LDAP details to enable LDAP user authentication. In case you're not aware of the specific credentials, kindly check the same from an authorized  administrator.

A sample illustration below will give you the look and feel of how the LDAP settings should look like.

#-------------------------------------------------------------------------------------------------
# LDAP related settings
sonar.security.realm=LDAP
sonar.security.updateUserAttributes=false
ldap.url=ldap://17.16.10.14:389
ldap.bindDn=CN=BUILDER,OU=USERS,OU=AdminPRivilege,DC=company,DC=com
ldap.bindPassword=ldap-password-here
ldap.user.baseDn=dc=company,dc=com
ldap.user.request=(&(sAMAccountName={login}))

Note that the above values are just an example and will vary for each organization. For more information, kindly check the LDAP plugin page here.

Wednesday 4 October 2017

How to generate report to list unused dependencies in Maven

In this post, we will see how to generate a report to list the unused dependencies of a Java project built using Maven.

We will use the dependency plugin to do so. Let's use the dependency:analyze-report goal as below

mvn dependency:analyze-report -DignoreNonCompile=true

This will basically generate an HTML report containing the list of dependencies with the following classification :

  • used and declared.
  • used and undeclared.
  • unused and declared.

Ideally, it's always a good idea to cleanup the pom's by removing and/or commenting the unused but declared dependencies.

Tuesday 3 October 2017

How to deploy specific file to Artifactory using Maven from Jenkins

This post will be helpful in a scenario where you are required to deploy i.e upload just a specific individual file (eg: xyz.zip or abc.jar) to Artifactory using Maven from Jenkins.

For illustration, configure a deploy-file job in Jenkins and add the following Maven goal.

clean deploy:deploy-file
-DgroupId=com.company.abc.message -DartifactId=message -Dversion=${version}
-DgeneratePom=false
-Dpackaging=jar
-DrepositoryId=artifactory
-Durl=http://17.16.18.12:8080/artifactory/simple/libs-release-local/
-Dusername=admin -Dpassword=admin-password
-Dfile=C:\Users\ironcladzone\Desktop\messageTest\message-${version}.jar

This will basically upload the message jar with a dynamically passed version parameter. Assuming the ${version} parameter value is defined 5.3.2 in Jenkins, the above command will essentially deploy message-5.3.2.jar to the libs-release-local repository.

Ciao!

Version increment and/or update using Maven

In today's fresh post, we will look into how to increment and/or update version numbers in pom.xml of your project using Maven.

Let's assume your project has a multi-module/multi-component setup. Each of the module/component has its own pom.xml with a list of dependencies and the overall bill of materials in general.

As a good practice, it's always a good idea to have about 2 pom's on the topmost levels. 1st pom should have all the project dependencies, which will be the parent pom of all modules. The 2nd pom should contain all third party non-project dependencies. This 2nd toplevel pom should be the parent of the 1st toplevel pom. These 2 toplevel pom's collectively define the project and 3rd party dependencies. Note that the versions of all dependencies should be defined in these 2 pom's. The individual module pom's should not carry the version number of dependencies. It will fetch them from the above 2 toplevel pom's.

Also, the module's own version should not be explicitly defined within it's own pom. It should only carry the version of it's parent pom. The below diagram should you help you visualize the ideal structure.

Let's say for instance the current version in current sprint is 5.3.3-7 and you want to update the version to 5.3.4-1 for going on to the next sprint. The following command can get that job done.

  • mvn versions:set -DnewVersion=5.3.4-1


Note however, that if your source code is under version control (for eg: IBM Clearcase), you may want to check out the files first, then update the versions in pom.xml and then check them in. In such a scenario, use the following sequence of commands to do so :

  • cleartool find . -name pom.xml -exec "cleartool co -nc %CLEARCASE_PN%"


This will recursively checkout all pom.xml files within your Clearcase view.
  • mvn versions:set -DnewVersion=5.3.4-1
This will increment all pom versions to 5.3.4-1
  • cleartool find . -name pom.xml -exec "cleartool ci -nc %CLEARCASE_PN%"
Once the versions are updated, all you have to do is recursively checkin all the pom.xml's. The above command will do that. 

Please note that the above cleartool commands will only work if you're using IBM Clearcase for source control.

For any questions, queries or discussion's kindly drop a comment or two. Peace. Cheers!

How to manually install a plugin in Jenkins

Sometimes in corporate environments, accessing certain things from the internet is blocked by the firewall due to restricted access. In case if you ever come across such a scenario, wherein you are not able to install a plugin in Jenkins due to firewall and/or proxy issue, you always have a workaround to manually install the plugin.

Firstly go to the specific plugin page and download it. For instance, consider the Email-ext plugin page for Jenkins and download it. It will have .hpi extension.


Now go the plugins configuration in Jenkins i.e Manage Jenkins => Manage Plugins => Advanced.
Here you'll see the option to upload the plugin .hpi file

Hope it helps. Cheers!

Print Area of a circle using Python

Let us write a small program today to print the area of circle in Python. The program will accept user input in the form of radius of the circle. There is a constant pi whose value we will be set to 3.142

Code :

print ('Program to calculate area of circle \n')

pi = 3.142
r = float(input('Enter radius : '))

a = pi*(r**2)

print ('Area of circle :', a )

Output :


OR


How to get username from IP address of remote computer

On a network (Home LAN or WiFi or corporate intranet), it is possible to get username from the assigned IP address of a remote machine. Assuming you have a bunch of users using Windows machines on the same network, lets look into the windows command to get the username.

For example, type the following in command prompt :

wmic.exe /node:17.16.15.28 computersystem get username
UserName
IRONCLADZONE\Special.User

Note that this works only for the remote machines which are connected on the same network.

Customized Build email notifications in Jenkins

When using Jenkins for automated builds, as most of you guys may be aware, we can setup SMTP settings for email notifications of build related events. We will cover the topic of SMTP setup in another separate post. In this post, let us just stick to the email customization part. Note that the SMTP settings must be configured in Jenkins for this plugin to work smoothly. For customized email notifications, we will use the Email-ext plugin to replace the default Jenkins'email settings.

With this plugin, we can setup email settings for various trigger conditions like a successful build, aborted build or a build failure etc.


In today's illustration, we'll cover the notification for Failure - Any trigger. In other words, Jenkins will fire a notification the moment there is any kind of build failure. We will use the HTML formatting in the notification. Use the following variables in the job configuration as shown in below screenshot.


In the Content field, try the following piece of code as below :


As you see, we include information like the Jenkins job URL, the cause of the failure which will be a short description of the error, the changes that went into the build and a link to the console URL.

Note the line which includes a regex - we basically do a simple pattern matching i.e we look for the words "BUILD FAILURE" and then display only that part from the build error. In better words, we truncate the verbose build log and show only the relevant error information in the mail notification.

${BUILD_LOG_REGEX, regex="^.*?BUILD FAILURE.*?$", linesAfter=10, matchedLineHtmlStyle="width:100%", showTruncatedLines="false", defaultValue="For detailed information, please check job console link below to find cause of failure"}  

Apart from this, the plugin also allows us to optionally attach the build log. However note that the build logs usually tend to be of big sizes (depending on the size of the project) and could fill your mailboxes fast.


Now with the email notification configured, let us look into how the notifications will actually look like. So here's the output - check the screenshot below :



Signing out for now. Hope it helps. Ciao guys!
Related Posts Plugin for WordPress, Blogger...
eXTReMe Tracker