Public Repository

Last pushed: a year ago
Short Description
The CI solution recommend by CI&T's Accelerate Squad team.
Full Description

Jenkins-Container

Introduction

A Docker image, built from Jenkins official one, including Docker itself (to be used by all the jobs), some already configured recommended plugins and a generator, to generate jobs, pipelines and view for any project.

Running

Since Jenkins-Container is available through Docker Hub, with Docker installed and running, run the following command:

docker run -p 8080:8080 -p 50000:50000 \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v $HOST_JENKINS_HOME:/var/jenkins_home \
  asqd/jenkins-container
  • -p 8080:8080: Publish the Jenkins web interface port.
  • -p 50000:50000: Publish the Jenkins slave agent port.
  • -v /var/run/docker.sock:/var/run/docker.sock: Share the host's Docker socket with the container's one, allowing the container to run other containers on the host.
  • -v $HOST_JENKINS_HOME:/var/jenkins_home: Specific directory on the host machine where all data from Jenkins will be stored.
    Important notes:
    1. Do not use a named volume. The bash script responsible for the docker run command on jobs needs it to be a bind-mount directory.
    2. If you are using Docker on Mac or Windows, you should only use directories under /Users (OS X) or C:\Users (Windows). More info in the official documentation.

How does it work?

A brand new Jenkins-Container have only one job called _Generator. Build it for every project or module you desire, each one with it own Git repository, and it will generate default jobs, pipeline and views for it.

Right out-of-the-box the generated jobs and pipeline of Jenkins-Container expects to find a .jenkins-ci.yml file into the root of the Git repository. This file should look like the example above:

build:
  container: maven:3-jdk-8
  options: -e ENV_VAR="some value"
  script:
    - mvn clean install -DskipTests
test:
  container: maven:3-jdk-8
  script:
    - mvn test
analysis:
  script:
    - echo "This is the analysis step."
dev:
  copy: build/libs/*.war
  script:
    - echo "Deploy do development server."
  • build|test|analysis|dev|qa|stage|release: Required. Build step into the default jobs/pipeline.
    • container: Optional. Docker image tag to be used by Jenkins to run the scripts build.
    • options: Optional. Options to be passed to docker run command. Useful for mapping cache volumes of build tools, like .m2 directory for Maven, for example.
    • copy: Optional. Files to be copied from the build step. Does't work on build step itself.
    • script: Required. List of bash commands to be executed into the job workspace directory, inside or not a Docker container.

When container is informed, Jenkins will start and run a Docker container on the host machine, and not inside its container. This way, all images cache will be kept at the host's Docker structure and will not be downloaded again.

Also, all containers started by Jenkins will start at the job's workspace directory, exactly as Jenkins would do normally.

If needed, the host's directory mapped to be used as JENKINS_HOME inside the container is available through the environment variable $HOST_JENKINS_HOME.

References

Besides Jenkins and Docker official images as base to Jenkins-Container's Dockerfile, to parse the YML file, expose its properties as environment variables and execute the docker run commands, among other things, Jenkins-Container makes use of Accelerate Squad's SCM-CI Scripts project.

Docker Pull Command
Owner
asqd

Comments (0)