Jenkins 101


Kevin Howell

2019-06-16 - Southeast Linux Fest

Jenkins 101 - Goals


Gain a basic understanding of Jenkins

Learn how to install & manage Jenkins

Learn some Jenkins best practices

Jenkins 101 - About Me


khowell@redhat.com (or kevin@kahowell.net)

https://github.com/kahowell

https://kahowell.net

Red Hat Certified Architect

Senior Software Engineer & tech lead for Candlepin & subscription-manager team at Red Hat (Satellite 6)

Jenkins 101 - What is Jenkins?


Jenkins is a widely used open source automation server

Indicated, common use is to use Jenkins to build and test software

Jenkins can be used as a general purpose tool for centrally executing tasks

Jenkins functionality is provided by a community of plugins

Jenkins 101 - The Server




The Jenkins server can run anywhere that Java runs.

Jenkins creates packages for many platforms:

  • Linux
    • RHEL, Centos, Fedora
    • OpenSUSE
    • Ubuntu, Debian
    • Container Image
  • Windows
  • macOS

Jenkins 101 - Installation


Use your favorite package manager (https://jenkins.io has packages for nearly everything).

Run a VM image

Run a container image

Jenkins 101 - Server Interface


The primary way to interact with the server is through its Web interface, e.g. http://localhost:8080.

Jenkins 101 - Jenkins Nodes


It's best practice in Jenkins to use systems other than the server in order to execute tasks.

Security

Stability

Isolation

Cross-platform automation

Jenkins 101 - Types of Jenkins Nodes


There are many ways to use systems as Jenkins nodes:

The Jenkins server itself is a Jenkins node

SSH to system with Java installed

Jenkins 101 - Types of Jenkins Nodes


Provision and deprovision an on-premise VM on-demand (e.g. via OpenStack)

Jenkins 101 - Types of Jenkins Nodes


Provision and deprovision a cloud-provider VM on-demand (e.g. via Amazon EC2)

Jenkins 101 - Types of Jenkins Nodes


Provision and deprovision containers or pods on a specific system on-demand

Jenkins 101 - Freestyle Jobs


The original method of defining execution via Jenkins is the Job.

Jobs are broken up into several components:

Job configuration (e.g. git configuration, parameters)

Triggers

Build Actions

Post-Build Actions (e.g. send email)

Jenkins 101 - Freestyle Job Example - Web Interface


Jenkins 101 - Freestyle Job Example - Job DSL


Snippet from https://github.com/candlepin/candlepin-jobs/blob/8431af34901ee547f0d79474665dc76e28e7a308/src/jobs/submanVagrantUpstreamImagesJob.groovy:

job("$baseFolder/vagrant-upstream-images") {
    description('builds centos, fedora, etc. vagrant images for subman development')
    label('rhsm-packer')
    scm {
        github('candlepin/packer', 'master')
    }
    wrappers {
        colorizeOutput()
        credentialsBinding {
            string('VAGRANT_CLOUD_TOKEN', 'VAGRANT_CLOUD_TOKEN')
        }
    }
    steps {
        shell(readFileFromWorkspace('src/resources/subman-vagrant-images.sh'))
    }
}

Jenkins 101 - Pipelines


The preferred, modern way of automating with Jenkins is by implementing Jenkins pipelines.

It was once common practice to create software pipelines by chaining Jenkins jobs together, but now pipelines are a first-class concept in Jenkins.

Jenkins 101 - Example Pipeline


pipeline {
    options { buildDiscarder(logRotator(numToKeepStr: '50')) }
    agent {
        label 'rhsm'
    }
    stages {
        stage('Clean') {
            steps {
                sh './gradlew --no-daemon clean'
            }
        }
        stage('Build') {
            steps {
                sh './gradlew --no-daemon assemble'
            }
        }
        /* more stages omitted */
    }

    post {
        always {
            archiveArtifacts artifacts: 'build/reports/checkstyle/*.html'
            junit 'build/test-results/**/*.xml'
        }
    }
}

Jenkins 101 - Pipeline Advice


Use the "declarative" syntax when possible

Use script files (.sh, .py)

Jenkins 101 - Jenkins as a Central Script Runner


Centralized way to run scripts

Empower people to use root powers, without giving them root.

Share output with colleagues easily

Keep a history of who and what

Jenkins 101 - Jenkins for Continous Integration


Use Jenkins to test incoming changes:

Unit tests

End-to-end tests

Static analysis

PRs or long-lived branches (e.g. master)

Jenkins 101 - Jenkins for Continous Delivery


Use Jenkins to automate building and releasing your products:

Automate builds on various platforms

Automate delivery to a CDN

Automate deployment of a service

Jenkins 101 - Recap


  • Jenkins can be used for lots of kinds of automation
  • Plugins can be installed to provide additional functionality
  • Jenkins nodes allow you automate various platforms and isolate your automation
  • Pipelines should be used for new automation

Jenkins 101 - Q&A & Thank You!


Thanks for attending! Questions?