Thursday, November 16, 2017

Fix Jenkins SMTPSendFailedException on Windows and Ubuntu 16.04

Intro

By default, Jenkins has disabled mail.smtp.starttls option and if you want to send notifications through any SMPT service which requires TLS, for example, through Gmail SMTP server, you need to enable this option. If the option is disabled you receive the following exception:

com.sun.mail.smtp.SMTPSendFailedException: 
530 5.7.0 Must issue a STARTTLS command first. q15sm1393424wra.91 - gsmtp 

Fixing SMTPSendFailedException on Windows

1. Navigate to Jenkins installation folder. To find out exact installation folder you need to navigate to 'Manage Jenkins' page and check 'Home directory' property. By default home directory should be 'C:\Program Files (x86)\Jenkins'
2. Open 'jenkins.xml' and add '-Dmail.smtp.starttls.enable=true' to arguments. See XML-code snippet below:

<executable>%BASE%\jre\bin\java</executable>
<arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -Dmail.smtp.starttls.enable=true -jar "%BASE%\jenkins.war" --httpPort=8080 --webroot="%BASE%\war"</arguments>

3. Restart Jenkins by navigating to {base_jenkins_url}/restart URL.

Fixing SMTPSendFailedException on Ubuntu 16.04

Basically, the steps are pretty the same as for Windows. First of all you need to figure out where Jenkins stores it configuration. By default, it should be '/etc/default/jenkins' file.

1. Open '/etc/default/jenkins' file.
2. Add '-Dmail.smtp.starttls.enable=true' to Java arguments.

# arguments to pass to java

# Allow graphs etc. to work even when an X server is present
JAVA_ARGS="-Djava.awt.headless=true -Dmail.smtp.starttls.enable=true"

3. Restart Jenkins by navigating to {base_jenkins_url}/restart URL.

Wednesday, October 18, 2017

Configure Jenkins and Xvfb plugin on Ubuntu

Introduction

Some build workflows in Jenkins require the display. If you run the build of Java application in console following exception might happen.
Exception in thread "main" java.lang.InternalError: Can't connect to X11 window server using '' as the value of the DISPLAY variable.
I found a solution how to fix it using  Xvfb.

Installation of Xvfb

1. To install Xvfb run following command in terminal.
sudo apt-get update
sudo apt-get install xvfb

Installation of Xvfb Plugin

1. I have an assumption that Jenkins is installed and running on Ubuntu 16.04. Please follow installation instructions to install Jenkins in case you do not have running Jenkins. 
2. Install Xvfb plugin. Please follow instructions for plugins installation.


Configuration of Xvfb Plugin

If plugin configured incorrectly you might have the following exception:
ERROR: No Xvfb installations defined, please define one in the configuration. Once defined you’ll need to choose one under Advanced options for Xvfb plugin job settings and save job configuration.
To fix it:
1. Navigate to  Manage Jenkins → Global Tool Configuration → Xvfb installation
2. Set Name: Xvfb
3. Set Directory in which to find Xvfb executable: /usr/bin


Xvfb installation

Troubleshooting

1. In case you still have the issue, try to play with the configuration of 'Start Xvfb before the build, and shut it down after.' step. E.g.

'Start Xvfb before the build, and shut it down after' step

Tuesday, October 17, 2017

Recursively copy files of a specific folder into a single flat folder on Windows

Recursively copy files of a specific folder into a single flat folder on Windows

Use following script, with appropriate folders.

@echo off
for /r "{full path to source dir}" %%a in (*) do copy "%%a" "{full path to flatten dir}"

Thursday, October 5, 2017

VirtualBox: Accessing shared folder from Ubuntu guest

Preconditions

  • VirtualBox is installed.
  • Ubuntu 16.04 is running in VirtualBox.

Instruction

1. Create shared folder. Click settings → Shared Folders → Click 'Add a new shared folder' button.

Shared folders

2. Specify name and path to the folder you want to make shared.

Add shared folder

3. In VirtualBox click 'Devices' → Insert Guest Additions CD image → Run with sudo permissions VBoxLinuxAdditions.run program from mounted disk.

VBoxLinuxAdditions.run

4. Make folder

sudo mkdir /home/{user_name}/shared-folder 

5. Mount the folder with the command:

sudo mount -t vboxsf {folder_name_from_step_2} /home/{user_name}/shared-folder

6. Done.

Thursday, September 21, 2017

Creating local network with internet access using VirtualBox and Ubuntu 16.04

Preconditions

VirtualBox is installed. Download link.
Ubuntu 16.04 server is downloaded. Download link.

Creating a virtual machine

1. Run VirtualBox and click 'New' button.
2. Specify virtual machine name.

Setting name and operating system.

3. Set RAM (Depending on your purpose it could be any value).

Memory size setup.

4. Select 'Create a virtual hard drive now'.

Hard drive setup.

5. Select VDI.

Hard drive file type setup.

6. Select 'Dynamically allocated'.

Storage on physical hard drive.

7. VirtualBox tries to store the image of the hard drive on disk C, so I recommend to change that and save the image on another logical hard drive.

File location and size.

8. Click 'Create' button.

Installing Ubuntu 16.04 server

1. Select the virtual machine and click 'Settings' button on the left top corner of the window.
2. Open 'Storage' settings → for IDE controller select download Ubuntu 16.04 image.

Storage settings.

3. Make sure that network settings have 'Attached to' set as NAT. We need this for ubuntu installation, in other mode operation apt-get might not work (see Troubleshooting section for more info).

Network settings.

4. Start the virtual machine and follow Ubuntu installation instructions, they are pretty straightforward.

Ubuntu 16.04 installation.


Configuring the virtual machine to work on the local network with internet access.

Now we are ready to configure our virtual machine. To do that follow instructions below:
1. Select the virtual machine and click 'Settings' button on the left top corner of the window.
2. Open 'Network' settings → in 'Attached to' select 'Bridged Adapter'.

Network settings. Bridged apapter.

3. Boot the server.
4. Open /etc/network/interfaces with any text editor.

 sudo nano /etc/network/interfaces

5. Set Ip address and DNS server for the server using the following configuration (NOTE: change IP address in case you are configuring multiple servers).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto <your network>
iface <your network> inet static
        address 192.168.1.2
        netmask 255.255.255.0
        gateway 192.168.1.1
        dns-nameservers 75.75.75.75 75.75.76.76
        dns-search local

Troubleshooting

1) If apt-get command does not work due to IPv6 issue. Please follow instructions below to fix it.
https://askubuntu.com/a/787491/733897 

Tuesday, May 23, 2017

Online stopwatch


00:00:00.000
Start Stop Reset
S - start or stop, ESC - reset