emerout / jenkins2-pipeline-maven-docker

Code/Slides about Maven jobs in Docker containers with Jenkins2 & Pipeline

Home Page:http://mgreau.com/jenkins2-pipeline-maven-docker/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Talk about Jenkins 2 Pipeline with Docker for Maven CI

This repository contains all resources about this talk:

  • slides: sources for AsciiDoc slides

  • docs: public files, slides HTML (assets, html…​)

  • demo: docker compose files and doc to run the demo

How to work on slides with livereload feature?

  1. Start the container

    $ docker-compose up -d
    $ open http://localhost:8000
  2. Edit slides (.adoc files) in slides/src/

  3. Save

  4. Refresh your browser and enjoy ;)

Run the Demo

Start Jenkins2 / Sonar containers

Create a network
$ docker network create --driver bridge swf

# Run Sonar
# user: admin
# pwd: admin
$ docker-compose -f demo/sonar/docker-compose.yml up

# Run Jenkins
# user: administrator
# password: password4Admin
$ docker-compose -f demo/jenkins2/docker-compose.yml up
$ open http://localhost:8888

Configure the Jenkins instance

A lot of configuration is loaded by default in the mgreau/jenkins Docker image, but some configuration have to be done once Jenkins is started.

Create an Agent (ci-agent))

  1. Configure the agent so that it can access the Docker daemon, by configuring the agent startup

    1. Go to http://localhost:8888/computer/new to create a new agent

      1. Name:: ci-agent

      2. Description:: Agent used to execute Build in Docker containers

      3. Remote root directory:: jenkins-agents/ci-agent

        This is a path to your filesystem (here ~/jenkins-agents/ci-agent).
        You can set an absolute path.
      4. Labels:: ci-docker

      5. Launch method:: Launch slave agents on Unix machines via SSH

        1. Host:: Your IP (no 127.0.0.1 neither localhost)

        2. Credentials:: Add new credentials with your username/pwd

        3. Advanced > Prefix Start Slave Command:: source ~/.bash_profile &&

          Required so that Jenkins can load your PATH to be able to access the docker binary

Configure a Gmail SMTP

In order to receive builds status by email, you need to configure, got to Extended E-mail Notification Configuration

SMTP server

smtp.gmail.com

Use SMTP Authentication

YES

User Name

YOUR EMAIL

Password

Email Account Password (or app password if you have 2 key auth)

Use SSL

YES

SMTP Port

465

Charset

UTF-8

📎

If you don’t do it, the pipeline will failed at the last step, but other steps will be ok.

Execute the default Pipeline/Maven/Docker build

By default, a Jenkns Pipeline job is created at http://localhost:8888/job/javaee7-websocket-master-ci/

It will build a Maven Java EE 7 project in a exoplatform/ci:jdk8-maven32 Docker container.+

The first time you execute this job, it will failed for security reason. You just have to Approve the Pipeline Script Then you can re-execute the pipeline.

Advanced configuration

Maven Settings file

If you want to customize the Maven Settings file included in each container:

  1. Update the Maven configuration file (settings.xml with ID exo-ci-maven-settings)

    1. Go to http://localhost:8888/configfiles/editConfig?id=exo-ci-maven-settings

    2. Update the Maven XML config file with your configuration

      jenkins setup maven config xml

Create your first Pipeline Docker job

  1. Create a new job

    1. Name::

    2. Type:: pipeline

  2. Submit

  3. Configure

    1. Pipeline script

@Library('github.com/mgreau/exo-pipeline-library@master') // (1)
import exoCI // (2)

node('ci-docker'){

    exoCI{
        gitUrl = 'https://github.com/mgreau/javaee7-websocket.git'
        gitBranch = 'master'
        dockerImage = 'exoplatform/ci:jdk8-maven32'
        mavenGoals = 'clean package'
    }
}
  1. This library is initialized in the default mgreau/jenkins2 Docker image, so this line is not mandatory

  2. The functions are automatically loaded in the default mgreau/jenkins2 Docker image, so this line is not mandatory

About

Code/Slides about Maven jobs in Docker containers with Jenkins2 & Pipeline

http://mgreau.com/jenkins2-pipeline-maven-docker/


Languages

Language:Groovy 39.6%Language:CSS 37.0%Language:JavaScript 19.7%Language:Shell 3.5%Language:HTML 0.2%