Jenkins: A Comprehensive Guide to the Open-Source CI/CD Tool
Foreword
Jenkins has become a leading choice for open-source continuous integration (CI)/Continuous Delivery (CD) solutions. In this article, we will explore the basics of Jenkins, its installation, and getting started with the tool. We will also delve into the different types of jobs, pipeline creation, and tips for using Jenkins effectively.
Update History
February 12, 2019 - The first draft of this article was read.
Jenkins Profile
Jenkins is a powerful, omnipotent CI/CD open-source software leader, providing over 1000 plug-ins to support construction, deployment, automation, and meet the needs of any project. With its user-friendly interface and extensive documentation, Jenkins has become a favorite among developers and DevOps teams.
Jenkins Installation
Jenkins comes in two versions: the long-term support (LTS) version and the update weekly version. Depending on your organization’s needs, one version may be more popular than the other. Both versions can be downloaded as .war files, native package installation programs, or Docker container distributions.
Recommended Installation
We recommend installing the LTS version, as it is more stable and suitable for demonstration environments. To install Jenkins on CentOS 7, follow these steps:
- Install Java 8:
yum install java - Download the Jenkins LTS version:
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repos - Import the Jenkins key:
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key - Install Jenkins:
yum install jenkins - Start Jenkins:
service jenkins start - Initial Configuration Wizard:
http://192.168.56.103:8080/cat /var/lib/jenkins/secrets/initialAdminPassword
Jenkins Getting Started
The Main Types of Jobs
Jenkins offers several types of jobs, each with its own strengths and weaknesses:
- Freestyle Project: A general project that can be used for a variety of tasks.
- Maven Project: A project-specific type that is similar to Freestyle but simpler.
- Multi-configuration Project: A project that requires more configuration items, such as environment and platforms.
- Pipeline Project: A project that is suitable for pipeline (workflow) plug-in function to construct a pipeline task.
- Multibranch Pipeline: A project that creates multiple pipeline projects based on SCM repository branches.
Project Specifications Required Configuration
This specification is particularly suitable for large projects that share the same scene. It includes:
- Project naming conventions: Setting item description.
- Historical building cleanup rules: Setting building node Label.
- E-mail notification: Common plug-ins.
Common Plug-ins
Jenkins offers several common plug-ins, including:
- Jenkins Backup Strategy: A combination of rsync backup distal.
- Jenkins Timed Backup: ThinBackup.
- Send e-mail plug-ins: Email Extension Plugin.
- Space bleaching extensions: Distributed Workspace Clean plugin.
Create the First Job
To create the first job, follow these steps:
- Install the Timestamper plug-in:
Plugin Manager→available plug-ins→search→timestamper→Install without restart. - Create a new type of job:
Freestyle→General Project→Name: My-first-freestyle-demo. - Build Environment:
Build Environment→Select→Add timestamps to the Console Output. - Build construction:
the screen print "This is my first Jenkins Job, oops". - Post-build build operation after Actions:
none. - Click
constructed immediately.
Jenkins Pipeline Introduction
The Pipeline is a set of workflow framework running on Jenkins, originally run independently connected to a single or a plurality of nodes of tasks, the task is difficult to implement a single orchestration of complex, and visualization. Pipeline is the core characteristic Jenkins2.X, helping Jenkins CI to achieve the transition from the CD and DevOps.
Jenkins Pipeline Starter
Pipeline script is implemented by the Groovy language - without any special training Groovy. Pipeline supports two grammar - Declarative declarative (introduced in Pipeline plugin 2.5 in) - Scripted Pipeline scripted.
Quickly Create a Simple Pipeline
To quickly create a simple pipeline, follow these steps:
- New Job:
Jenkins→New→Enter the Job name: "My-first-pipeline-demo"→select Pipeline→click "OK". - Configuration:
In the Pipeline→Enter the following statement→Script text input box→click "Save". - Building immediately:
pipeline { agent any stages { stage ('Build') { steps { echo 'Build' } stage ('Test') { steps { echo 'Test' } stage ('Deploy') { steps { echo 'Deploy' } } } } }
Jenkins Forgot Password How Do
If the permissions set incorrectly, or forget the password, resulting in admin himself unable to land Jenkins how to do?
- Command line to stop Jenkins.
- Back up
$JENKINS_HOMEthe config.xml. - Opened by the editor
$JENKINS_HOMEin the config.xml. - The true elements true to false.
- And delete the content elements.
- Command line to start Jenkins.
Ansible Jenkins API Token Tips
Jenkins REST API provides the API token, authentication makes it possible to use the API token in your program (instead of using your actual password). API token can be viewed in the user interface to the user’s personal settings → user id → Settings page, click Show API token in API Token button area, you can view the API token, but also can change the API token.
Reference Content
The official handbook will always be your best reference. Jenkins User Manual - Jenkins 用户手册
Author
Wang Austrian OX link: Jenkins 学习使用实践 - 简书 Source: Jane books