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. Simply start gitbucket: java -jar gitbucket.war

Clone this wiki locally