Jenkins

Install: Using docker to run jenkins container

There is an official jenkins image that can help you install jenkins rapidly. After installed docker, you just need to run

$ docker pull jenkins

to download jenkins image, and then run

$ docker run --name jenkins -p 8080:8080 -p 50000:50000 jenkins

to quickly run jenkins in your host. Port 50000 is used to connect a slave agent.

All Jenkins data lives in folder /var/jenkins_home. We usually attach a volume to save data:

$ docker run -p 8080:8080 -v /var/jenkins_home /path/to/host/jenkins/workspace

By the way, we can always using

$ docker cp jenkins:/var/jenkins_home /path/to/host/backup/workspace

to backup the directory.

Configure: Using jenkins-job-builder to yamlize job configurations

Jenkins Job Builder takes simple descriptions of Jenkins jobs in YAML format, and uses them to configure Jenkins. You can keep your job descriptions in human readable text format in a version control system to make changes and auditing easier. It also has a flexible template system, so creating many similarly configured jobs is easy.

One thing I’ve found really helpful is Variable References powered by yaml:

  • pass an object (boolean, list or dict) to template
  • Using anchors and Alias to references to variables in template.

Example:

- scm:
    name: site-repo
    scm:
        - git:
            url: http://github-enterprise.service.consul/site/site.git
            branches:
                - master

- default_logrotate: &default_logrotate
    name: "default_logrotate"
    logrotate:
        numToKeep: 100

- job:
    name: ark-ci-online
    <<: *default_logrotate
    node: master
    scm:
        - site-repo
    builders:
        - gfw
        - shell:
            !include-raw tools/qaci/online.sh
    publishers:
        - archive:
            artifacts: "online.tag,ark_service_online.rev"

There are also many configuration item for jenkins plugins. I will describe thems in next post.