Skip to content

automatic builds for maven, jenkins and gitbucket

Matthieu Brouillard edited this page Dec 7, 2017 · 7 revisions

Automate maven builds using Jenkins and gitbucket

This setup demo a full automation setup using nginx, gitbucket, Jenkins, Pipeline multibranch, Github branch source, webhooks and build statuses.

In this setup the goal is to:

  • fire a build for each commit, on every branch or on any PR
  • have different project versions per branch and PR
  • to have build statuses set on git commits

Environnement

All the setup below is provided as an example, adapt with recent versions and with your platform.
I built this setup on windows 10.

The services will be availabe at:

hosts

We will fake DNS names for gitbucket & jenkins services. Edit your hosts file, mine is under C:\Windows\System32\drivers\etc, add entries for the 2 services

127.0.0.1 jenkins.my.pc
127.0.0.1 gitbucket.my.pc

nginx

We will serve both services on port 80 using the server names defined above. For that we will a nginx reverse proxy.

Having a nginx-1.12.1 running instance, mine is installed under D:\dev\tools\web\nginx\nginx-1.12.1

Create NGINX_HOME\conf\ci.conf file.

server {
    listen 80;
    server_name jenkins.my.pc;
     
    location / {
 
      proxy_set_header        Host $host:$server_port;
      proxy_set_header        X-Real-IP $remote_addr;
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header        X-Forwarded-Proto $scheme;
 
      # Fix the "It appears that your reverse proxy set up is broken" error.
      proxy_pass          http://127.0.0.1:8090;
      proxy_connect_timeout   150;
      proxy_send_timeout      100;
      proxy_read_timeout      100;
  
      # Required for new HTTP-based CLI
      proxy_http_version 1.1;
      proxy_request_buffering off;
    }
}
  
server {
    listen 80;
    server_name gitbucket.my.pc;

    location / {
        proxy_pass              http://127.0.0.1:8080;
        proxy_set_header        Host $host;
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_connect_timeout   150;
        proxy_send_timeout      100;
        proxy_read_timeout      100;
        proxy_buffers           4 32k;
        client_max_body_size    500m; # Big number is we can post big commits.
        client_body_buffer_size 128k;
    }
}

edit NGINX_HOME\conf\nginx.conf, add an include to above file.

...
http {
   ...
   # Include CI specific setup for gitbucket & jenkins
   # put the include INSIDE the http tag
   include "D:/dev/tools/web/nginx/nginx-1.12.1/conf/ci.conf";
}
...

Restart/reload nginx: nginx -s reload

gitbucket

Here we will use a default installation of gitbucket using version 4.18.

Download gitbucket.war from 4.18 release.

  • start gitbucket: java -jar gitbucket.war
  • navigate to http://gitbucket.my.pc/
  • connect using root/root, then create users:
    • ci/ci: an administrator, will be used from jenkins
    • john/j: a simple user
    • bill/b: another simple user

jenkins

Download Jenkins and run it using java -jar jenkins.war --httpPort=8090

I personally skipped default installation and then manually added:

  • GitHub Branch Source Plugin 2.3.1
  • Pipeline: Basic Steps 2.6
  • Pipeline: Model API 1.2.5
  • Pipeline: Multibranch with defaults 1.1
  • Pipeline: Nodes and Processes 2.17
  • Pipeline: Shared Groovy Libraries 2.9
  • Pipeline: Stage Step 2.3

Configure jenkins:

Manage Jenkins > Configuration

  • Jenkins url: http://jenkins.my.pc/
  • Add a Github Enterprise Server:
    • API endpoint: http://gitbucket.my.pc/api/v3
    • Name: Gitbucket local jenkins configuration

Manage Jenkins > Global Tool Configuration

  • Add a git installation, point it to git.exe on your disk. A recent version of git.exe is required, because git.exe will have to follow http redirections ; my version is 2.14.2.windows.2
  • Add a JDK 1.8 installation, name it JDK 1.8
  • Add a Maven 3.3.x installation, name it Maven 3.3.x jenkins tools configuration
Clone this wiki locally