Jenkins, using Generic Webhook Trigger with pipelines

logo-title

Generic Webhook Trigger is a useful plugin for Jenkins to trigger jobs retrieving some parameters from webhook request, we can configure to do some actions like automate tasks and change their behavior.

In this example I’m gonna show how use it, if you want to install it please check the manage plugin section in your Jenkins instance.

Let’s start from the scratch: Hello Pipeline Message

Ok, first create a new Pipeline project Main page > new Item > Pipeline, and let’s start printing a simple a Hello Pipeline message. Seguir leyendo

Jenkins execute script over ssh

logo-title

To execute a shell script with jenkins into a remote server it’s very easy task, you can use a sshPublisher plugin or configure manually, in this entry I’m going to show how to do it using ssh key pair.

To avoid login prompt in command line, setup a ssh keys in your jenkins instance and copy the public key to the remote server.

Setup the autentication

1. Create a ssh key pair in your jenkins server, login into the jenkins server with the user that is currently running the application server and execute the ssh-keygen command:

sudo su -s /bin/bash jenkins
ssh-keygen -t rsa

Leave the options by default to create a file ~/.ssh/id_rsa, but take care if you have a previous one, this will be overwriten. Or you can set another name for the key pair, I’m going to use id_dummy without passhrase.

Output:

bash-4.2$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/var/lib/jenkins/.ssh/id_rsa): /var/lib/jenkins/.ssh/id_dummy
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /var/lib/jenkins/.ssh/id_dummy.
Your public key has been saved in /var/lib/jenkins/.ssh/id_dummy.pub.

Note: The passhrase is an aditional method to keep the keys safe in case that your lost it.

2. Copy the public key to remote server using the command ssh-copy-id

ssh-copy-id -i ~/.ssh/id_dummy username@remote_host

If the command it’s not available you can do it manually with this:

cat ~/.ssh/id_dummy.pub | ssh username@remote_host "mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys && chmod -R go= ~/.ssh && cat >> ~/.ssh/authorized_keys"
Seguir leyendo

Setup CI Server in Cloud for Java projects with code coverage and inspection

logos CI

Yep!  I was wating a long time to wirte about this topic, but finally I’m going to show  how to setup your own Continous Integration Server (aka CI) using cloud services, all of them with free accounts.

Only consider the scope of the functionality is very limited because all services we’re using are free, but if pay for it you can do much more.

I don’t going to explain what is or what are the feautres of the CI server, only I want to say the CI is a concept created by Martin Fowler in 2006 and like he’s mention in her website:

«Continuous Integration is a software development practice where members of a team integrate their work frequently, usually each person integrates at least daily – leading to multiple integrations per day. Each integration is verified by an automated build (including test) to detect integration errors as quickly as possible. Many teams find that this approach leads to significantly reduced integration problems and allows a team to develop cohesive software more rapidly.»

Well, let’s get started. We’re going to configure and integrate the next services, so you only need your Github or Bitbucket account.

The demo project

Seguir leyendo