Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Jenkins Quick Guide

Alex
June 15, 2019

Jenkins Quick Guide

Alex

June 15, 2019
Tweet

More Decks by Alex

Other Decks in Technology

Transcript

  1. 1. Code (Version Control System): Git, SVN 2. Build (Continuous

    Integration): Travis, TeamCity, DroneCI, CircleCI, Bamboo, Jenkins 3. Test (Continuous testing, inspection): JMeter, Sonarqube 4. Package (Artifact repository): Artifactory 5. Configure & Release ( Change management, containerization ): Docker Compose 6. Infrastructure ( Orchestration, cloud ): Kubernetes, Mesos, AWS, GCP, Nexus 7. Monitor ( Manage the performance): ELK, Grafana, Netdata Jenkins is a continuous integration tool for DevOps
  2. Why we choose Jenkins as our CI / CD tool

    1. An open source tool with great community support. 2. Has 1000+ plugins to ease our work. 3. Easy to install and use. 4. Great integration with other DevOps tools (e.g., GitLab, Jira, Slack, Docker) 5. Easy to archive artifact and deploy with custom scripts.
  3. How to Install Jenkins on CentOS 7 $ sudo yum

    -y install epel-release $ sudo yum -y install java-1.8.0-openjdk $ sudo yum -y wget $ wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins.io/redhat-stable/jenkins.repo $ rpm --import http://pkg.jenkins.io/redhat-stable/jenkins.io.key $ sudo yum -y install java-1.8.0-openjdk jenkins $ docker run -p 8080:8080 -p 50000:50000 -v /home/bagel:/var/jenkins_home jenkins # Method1: yum package manager # Method2: docker
  4. Useful Jenkins Plugins I • Ansible Plugin - integrated with

    Ansible • Blue Ocean - a new user experience for Jenkins • Copy Artifact Plugin - copy artifacts from another project • Docker Plugin - integrates Jenkins with Docker • GitLab Plugin - allows GitLab to trigger Jenkins and display results in the GitLab UI • Jira Plugin - update JIRA issues by jenkins • Monitoring - monitor jenkins itself
  5. Useful Jenkins Plugins II • Role-based Authorization Strategy - easy

    to manage team members’ authorization • Simple Theme Plugin - define the Jenkins themes by HTML , CSS and JavaScript • Slack Notification Plugin - publish build status to Slack channels • Git Plugin - integrates Git with Jenkins • GitHub Plugin - allows GitHub to trigger Jenkins builds • BitBucket Plugin - allows BitBucket to trigger Jenkins builds • Gitlab Merge Request Builder - integrates Jenkins with Gitlab to build Merge Requests
  6. Useful Jenkins Plugins III • JIRA Trigger Plugin - triggers

    a build when a certain condition is matched in JIRA • SSH Plugin - executes shell commands remotely using SSH protocol • HTML Publisher Plugin - Publishes HTML Reports • Pipeline Plugin - orchestrate CI / CD pipeline, simple or complex. • Performance Plugin - capture reports from popular testing tools (e.g., JUnit, JMeter) • Job DSL - allows the programmatic creation of projects using a DSL • Allure Plugin - generate test report and attach it to build during Jenkins job run
  7. Setup Jenkins Credentials: via SSH Jenkins > Credentials > System

    > Global credentials add your private key here
  8. Create a Simple Jenkins Pipeline - 4 Two ways to

    implement pipelines: • write pipeline script directly • Pull scripts from SCM (recommend: because the pipeline scripts can be stored in git repository)
  9. Jenkinsfile • Pipeline supports two syntaxes, Declarative (introduced in Pipeline

    2.5) and Scripted Pipeline. • Use apache groovy language to describe the pipeline. • You can use if, when, try/catch/finally or define helper functions to control the pipeline. pipeline { agent { docker 'maven:3-alpine' } stages { stage(“Stage 1”) { steps { sh 'mvn -B clean verify' } } } } Example of declarative pipeline
  10. Pull Artifacts (Copy Artifact Plugin) Pull the artifact from “Jenkins-example”

    job, artifact name is “stage.zip” (filter function support regex), and the selectors is “lastSuccessful”