Giter Site home page Giter Site logo

auto_jenkins's Introduction

Introduction

Jenkins is an automation server. Installing and configuring Jenkins itself shall be a fully automated process. That is the goal of auto-jenkins.

Currently, auto-jenkins does the following automatically:

  • Set up a Jenkins master in a Docker container, with a configurable list of plugins installed
  • Configure an SSH slave, which can be a physical host or any host accepting SSH connections

With the pipeline plugin (plugin id: workflow-aggregator), all the builds can be executed in a Docker container.

Docker is required on both the master host (host where the Jenkins master container is running) and the SSH slave. One physical host can be used both as the master host and as the SSH slave. For example, I ran the entire setup on a MacBook Pro, which is both the master host and the SSH slave.

Steps

All commands are run on the master host.

Prepare the home directory for the Jenkins master and generate its SSH key pair

mkdir -p /private/var/tmp/jenkins_home_master/.ssh
chmod 755 /private/var/tmp/jenkins_home_master/.ssh
ssh-keygen -t rsa -b 4096 -C "[email protected]" -f /private/var/tmp/jenkins_home_master/.ssh/id_rsa
ssh-keyscan slave.example.com >> /private/var/tmp/jenkins_home_master/.ssh/known_hosts

Allow SSH onto the slave1 using the generated key pair and prepare the work direcory for the Jenkins slave2

ssh-copy-id -f -i /private/var/tmp/jenkins_home_master/.ssh/id_rsa [email protected]
ssh -i /private/var/tmp/jenkins_home_master/.ssh/id_rsa [email protected] 'mkdir -p /private/var/tmp/jenkins_home_slave'

Create the extra-vars file to overwrite the defaults

cat ./ansible/extra-vars.json
{
  "jenkins_slave": {
    "name": "ssh_slave",
    "host": "slave.example.com",
    "port": 22,
    "path": "/private/var/tmp/jenkins_home_slave",
    "label": "ssh_slave_label"
  },
  "pk_cred": {
    "id": "pk_jenkins",
    "user": "your_user",
    "desc": "authorized key for ssh onto the slave host"
  }
}

Build the Jenkins master Docker image3

packer build jenkins.json

Prepare the environmental variables and run the Jenkins master container

cat ~/.auto-jenkins-env
PASSWORD=admin
USERNAME=admin

docker run -d -p 8080:8080 --env-file ~/.auto-jenkins-env -v /private/var/tmp/jenkins_home_master:/var/jenkins_home --rm --name auto-jenkins ouyi/auto-jenkins:0.0.1

Create a test pipeline job4

node('ssh_slave_label') {
    echo 'Hello World'
    withDockerContainer('alpine') {
        git url: 'https://github.com/ouyi/test'
        sh 'pwd && ls -lR && cat README.md'
    }
}

TODOs

  • Deploy in AWS
  • Multiple slaves
  • Reverse proxy with nginx

Footnotes

Footnotes

  1. Mac users might need to allow remote login

  2. Make sure the paths /private/var/tmp/jenkins_home_master and /private/var/tmp/jenkins_home_slave are added to "File sharing" under Docker preferences.

  3. Packer is required on the master host

  4. The jenkins public key ([email protected]) shall be added as deploy key to GitHub repo

auto_jenkins's People

Contributors

ouyi avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.