Jenkins CI/CD 2024

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

In Continuous Integration (CI), what is the primary goal regarding code changes?

  • To isolate code changes to individual developers.
  • To integrate code changes from multiple developers into a shared repository, regularly. (correct)
  • To delay integration until all features are complete.
  • To deploy code changes directly to production without integration.

Continuous Delivery (CD) focuses on what aspect of code changes?

  • Manually reviewing every code change before deployment.
  • Limiting code changes to a single environment.
  • Ensuring code changes are never deployed automatically.
  • Automatically deploying code changes to production or staging environments. (correct)

How do CI/CD pipelines contribute to modern software development?

  • By automating the entire software development process from code commit to deployment. (correct)
  • By reducing collaboration between development and operations teams.
  • By increasing the risk of production issues.
  • By slowing down the delivery of new features.

Which of the following is a key benefit of implementing CI/CD?

<p>Faster delivery of new features and bug fixes. (A)</p> Signup and view all the answers

What role does Jenkins play in CI/CD pipelines?

<p>It is an open-source automation server widely used for implementing CI/CD pipelines. (C)</p> Signup and view all the answers

What benefit does Jenkins offer regarding platform and language support?

<p>It is available for multiple platforms and programming languages. (A)</p> Signup and view all the answers

When creating your own Jenkins image, what does the use of a Dockerfile allow?

<p>Customizing Jenkins with specific plugins. (A)</p> Signup and view all the answers

Why might Docker-in-Docker (dind) be necessary when running Jenkins?

<p>To enable Jenkins to execute Docker commands inside Jenkins nodes in CI/CD pipelines. (B)</p> Signup and view all the answers

After starting Jenkins with Docker Compose, how can you access Jenkins for the first time?

<p>By unlocking it using an auto-generated password found in the Docker container logs. (D)</p> Signup and view all the answers

What should you do if your Jenkins Docker containers fail to start due to file access issues?

<p>Change the file access rights using <code>sudo chmod -R 777 jenkins-data</code>. (C)</p> Signup and view all the answers

When setting up Jenkins with ngrok, what is ngrok primarily used for?

<p>To provide a public URL for accessing the Jenkins instance. (D)</p> Signup and view all the answers

After installing Jenkins, what is the next typical step in configuring it?

<p>Customizing Jenkins with plugins. (B)</p> Signup and view all the answers

Which of the following is a characteristic of Jenkins 'Freestyle project'?

<p>It allows combining any SCM with any build system. (B)</p> Signup and view all the answers

In Jenkins, what is the purpose of treating credentials as 'secret parameters'?

<p>To restrict access to credentials for security. (A)</p> Signup and view all the answers

When configuring a 'Build periodically' trigger, what syntax is used for scheduling builds?

<p>Cron syntax. (C)</p> Signup and view all the answers

In Jenkins, what does adding a build step with ls -l accomplish?

<p>It lists all the files and directories in the workspace. (C)</p> Signup and view all the answers

What is Blue Ocean's primary purpose within Jenkins?

<p>To provide a simplified pipeline management and visualization tool within Jenkins. (B)</p> Signup and view all the answers

Before creating a new Pipeline with Blue Ocean, what type of credentials might you need to set up?

<p>GitHub or Docker Hub credentials. (B)</p> Signup and view all the answers

What file is primarily used by Blue Ocean to define a pipeline?

<p>Jenkinsfile (A)</p> Signup and view all the answers

What immediate benefit does storing a Jenkinsfile in source control provide?

<p>Code review and iteration on the Pipeline definition. (C)</p> Signup and view all the answers

Which of the following best describes the role of a GitHub webhook in a CI/CD pipeline?

<p>It triggers the Jenkins instance via HTTP POST when an event occurs in the GitHub repo. (B)</p> Signup and view all the answers

After setting up a GitHub webhook, what action will automatically trigger a new build in Jenkins?

<p>Making changes in the GitHub repository and committing them. (D)</p> Signup and view all the answers

In the Jenkins setup described, if the Jenkinsfile builds a Docker image, what other file is required in the repository?

<p>Dockerfile (C)</p> Signup and view all the answers

What is the primary function of Jenkins in the described CI/CD process?

<p>To build, test and deliver new versions of applications automatically. (A)</p> Signup and view all the answers

Consider a Jenkins pipeline defined to build and push a Docker image to Docker Hub. If changes are pushed to a 'dev' branch, but the Docker image is only intended to be pushed when changes are on the 'main' branch, how would you configure the pipeline?

<p>Modify the Jenkinsfile to conditionally execute the Docker image build and push steps based on the branch name. (B)</p> Signup and view all the answers

You have configured a Jenkins Freestyle project to build every minute. However, you notice that builds are occasionally failing because a dependent service is not always available. Which of the following approaches would BEST address this?

<p>Add a shell command to the build step that checks the availability of the dependent service before proceeding with the build. (B)</p> Signup and view all the answers

You are using Blue Ocean to create a Jenkins pipeline. You have a complex multi-stage pipeline that needs to be defined; some steps are easier to represent declaratively, and some require more procedural logic. How can you configure the Jenkinsfile to accomodate this?

<p>Nest scripted pipeline code blocks within a declarative pipeline structure, allowing for a mix of styles. (C)</p> Signup and view all the answers

A team is using Jenkins to automate deployments to a staging environment. They want to ensure that only code reviewed by at least two team members gets deployed. How can they incorporate this requirement into their Jenkins pipeline?

<p>Use a Jenkins plugin to integrate with the code review tool and only proceed if the code has the required approvals. (C)</p> Signup and view all the answers

Developers notice that certain Jenkins builds are consuming excessive resources and impacting overall performance. Which of the following strategies would BEST help address this issue?

<p>Implement resource limits (CPU, memory) for individual build steps using a Jenkins plugin or Docker. (C)</p> Signup and view all the answers

You set up a GitHub webhook to trigger a Jenkins build on every push. However, you notice that every commit in a pull request triggers a build, even though you only want to build the final merged code. How can you configure the webhook to avoid redundant builds?

<p>Change the webhook to only trigger on pull request merge events. (A)</p> Signup and view all the answers

After creating a new Jenkinsfile and setting up a Blue Ocean pipeline to use it, you realize that your pipeline is not correctly pulling dependencies because of an incorrect URL. Which option is the MOST effective way to address this issue?

<p>Correct the URL in the Jenkinsfile within the source code repository and commit the changes. (B)</p> Signup and view all the answers

You have a Jenkins pipeline that deploys a web application to multiple environments (development, staging, production). Each environment requires slightly different configuration settings (e.g., database connection strings, API endpoints). How can you MOST effectively manage these environment-specific configurations in your Jenkins pipeline?

<p>Use environment variables in Jenkins and externalize the configuration settings to environment-specific files or a configuration management tool. (B)</p> Signup and view all the answers

You are using Blue Ocean to manage your Jenkins pipeline, and you want to add a new stage to run security scans on your code. Which of the following is typically the BEST approach?

<p>Edit the <code>Jenkinsfile</code> directly to add the security scan stage. (C)</p> Signup and view all the answers

A Jenkins pipeline builds and tests a Java application. The build occasionally fails due to intermittent network issues during dependency resolution. What's a good strategy to improve the reliability of the build?

<p>Configure Maven or Gradle to use a local repository manager (e.g., Nexus, Artifactory) to cache dependencies. (C)</p> Signup and view all the answers

Which of the following is NOT a typical benefit of using Jenkins in a CI/CD pipeline?

<p>Manual code review enforcement. (C)</p> Signup and view all the answers

What command should be used to use docker compose?

<p><code>docker compose</code> (A)</p> Signup and view all the answers

What does the command sudo chmod -R 777 jenkins-data do?

<p>gives read write and execute permissions to jenkins-data folder (A)</p> Signup and view all the answers

What is Blue Ocean?

<p>a Jenkins plugin that provides an easy-to-use Pipeline visualization. (D)</p> Signup and view all the answers

Where is this file: /var/jenkins_home/secrets/initialAdminPassword?

<p>on the server. (A)</p> Signup and view all the answers

You need to install ngrok because...

<p>It will give you a public URL for access (B)</p> Signup and view all the answers

Flashcards

Continuous Integration (CI)

Integrating code changes from multiple developers into a shared repository regularly.

Continuous Delivery (CD)

Automatically deploying code changes to production or staging environments.

Continuous Deployment

Automatically deploying code changes to production after passing all necessary tests.

Jenkins

An open-source automation server widely used for implementing CI/CD pipelines.

Signup and view all the flashcards

Dockerfile

A file containing configuration for Jenkins to build an image.

Signup and view all the flashcards

Docker Compose

A configuration file for defining and running multi-container Docker applications.

Signup and view all the flashcards

Initial Admin Password

The file needed to unlock Jenkins after initial installation.

Signup and view all the flashcards

Jenkins Plugins

A Jenkins feature that extends functionality through additional tools.

Signup and view all the flashcards

GitHub Webhook

Automatically trigger a build in Jenkins when changes are pushed to a repository.

Signup and view all the flashcards

Freestyle Project

A Jenkins project type for simple, flexible job configuration.

Signup and view all the flashcards

Secret Parameters

A secret parameter treated with extra security in Jenkins.

Signup and view all the flashcards

Blue Ocean

A plugin that simplifies Jenkins pipeline management with visualization.

Signup and view all the flashcards

Jenkinsfile

A text file containing the definition of a Jenkins Pipeline.

Signup and view all the flashcards

Study Notes

  • Jenkins is for Continuous Integration and Delivery (CI/CD) and the notes are for 2024
  • The presentation includes work by Assoc. Prof. Panche Ribarski, PhD and Ass. Stefan Andonov, MSc

Agenda

  • Includes information about Jenkins, its installation, usage, and Blue Ocean, along with an introduction and a conclusion, as well as a class assignment or homework

Continuous Integration (CI)

  • Integrating code changes from multiple developers into a shared repository regularly
  • Helps catch integration issues early and ensures the codebase is always working

Continuous Delivery (CD)

  • Deploy code changes to production or staging environments automatically
  • Allows teams to rapidly deliver new features and bug fixes to end-users with minimal manual effort

Continuous Deployment

  • Automatically deploying code changes to production after passing all necessary automated tests and approvals

CI/CD

  • Is a critical aspect of modern software development.
  • Helps teams deliver high-quality software faster
  • Automates the entire software development process from code commit to deployment
  • Pipelines consist of building, testing, and deploying code changes

CI/CD Benefits

  • Faster delivery of new features and bug fixes
  • Reduced risk of production issues
  • Improved collaboration between developers and operations teams

Jenkins

  • Is widely used as an Open-source automation server for implementing CI/CD pipelines
  • Also provides a web-based UI for configuring and managing pipelines, with integration for various tools and plugins

Jenkins Benefits

  • Available for multiple platforms and programming languages
  • Integrates with various tools and services, for all stages of CI/CD pipelines

Installing Jenkins

  • Simplest way is using a Docker image and running them as a Docker container.
  • A ready-made Docker image is available on Docker Hub
  • It is possible to create a customers image
  • Creating an image allows customization with specific plugins
  • A Dockerfile in an empty directory called jenkins, can be created to customize

Docker Compose

  • Can be configured to build and run the image
  • Jenkins needs Docker-in-Docker (dind) to run in a container alongside in order to execute Docker commands inside Jenkins nodes in the CI/CD pipelines
  • Start the Docker orchestration with: docker compose up -d
  • Jenkins will be available at http://localhost:8080, or whichever port is defined in the .yml file
  • On first access, an auto-generated password is required to unlock the instance.
  • The auto-generated password can be found in the docker container logs: docker compose logs
  • If issues occur: sudo chmod -R 777 jenkins-data

Jenkins Plugins

  • After installation plugins can customize Jenkins
  • It is possible to "Select Plugins to Install” and add specific ones

Adding Jenkins Plugins

  • Dashboard View
  • Git Parameter
  • GitHub plugin
  • GitLab plugin
  • Blue Ocean
  • Keep preselected options (suggested plugins)

Admin User

  • Create the first admin user
  • To use a public URL setup ngrok and activate it for HTTP access to the Jenkins port

Ngrok

  • Use the public URL from ngrok in the setup

Using Jenkins

  • Create a Freestyle project
  • Add a GitHub project to it, via URL, then add GitHub credentials.
  • GitHub credentials are treated as secret parameters
  • Set periodic builds to one each minute
  • Add the command 1s -l as a simple build step (ls -l)

Jenkins and GitHub

  • Jenkins pulls the GitHub project each minute to "build"
  • The "build" can be a simple execution of ls -l, or multiple steps can be created and execute a Jenkins pipeline:
    • Run tests that the project works as intended
    • If the tests pass, build a Docker Image from the project
    • Push the Docker Image to a image registry (e.g. Docker Hub)
    • Notify another service (or server) that the Docker Image is ready to be pulled, and deployed on a development / production server

Blue Ocean

  • Used for simplified pipeline management
  • Is a standard plugin in Jenkins
  • Easy-to-use Pipeline visualization
  • Provides a Pipeline editor that guides the user through a visual process to create a Pipeline and makes the creation of Pipelines more approachable
  • Native integration for branches and pull requests, which enables maximum developer productivity when collaborating on code in GitHub and Bitbucket

Docker Hub

  • Requires Docker Hub credentials

New Pipeline with Blue Ocean

  • Start it by selecting where the code is store and creating a new pipeline with Blue Ocean
  • The pipeline is automatically created and executed after
  • It uses Jenskinsfile to define the Pipeline

Jenkinsfile

  • Is a text file that contains the definition of a Jenkins Pipeline and is checked into source control
  • It provides code review and iteration on the Pipeline.
  • Includes and audit trail for the Pipeline
  • Provides single source of truth for the Pipeline, which can be viewed and edited by multiple members of the project
  • The pipeline supports Declarative and Scripted syntaxes
  • Guidelines for creating a Jenkinsfile is further reading.

Jenkinsfile in GitHub

  • Builds a Docker Image of the repo, so a Dockerfile in the repo, is needed as well
  • The firsy build of the pipeline happened automatically
  • Explicit triggers can be set: for instance, when a commit/push/merge happens in the repo
  • Github is needed to ping a Jenkins instance whenever an event happens

GitHub Webhook

  • Set up a webhook in the GitHub repo that pings the Jenkins instance via HTTP POST with: Jenkins public URL + "/github-webhook/".
  • Ngrok is necessary to setup temporarily
  • After setting up the GitHub repository, Jenkins will automatically locate the appropriate Pipeline and will execute the Pipeline
  • Any changes in repo will execute the pipline with a new commit ID
  • The deatils of the pipeline run will show the Docker Image on Docker Hub

Automation with Blue Ocean and Jenkins

  • Jenkins can visualize our automated Pipeline with Blue Ocean
  • A Jenkins pipeline does the following:
  • Checks out the code from the GitHub repository
  • Builds the Docker Image, and
  • Publishes the Docker Image on Docker Hub

Conclusion

  • Jenkins streamlines the software development and deployment process by automating tasks
  • Offers customization, enabling development teams to adapt to their specific needs and workflows
  • Offers plugin ecosystem, integrates with tools and technologies
  • Enhnaces software quality and speed to market

Class Assignment / Homework: Setting up Jenkins

Part 1: Setup Jenkins on the machine
  • Can be done using the Dockerfile and the docker-compose.yml files
  • Other aspects of setup include installing plugins, create an admin profile, create an ngrok temporary public URL, setup your secret credentials (GitHub and Docker Hub)
Part 2: Create a Freestyle Project
  • Setup an automatic build
  • Simple GitHub repository from their account should be connected
  • Add a command 1s -l as a simple build step
Part 3: Blue Ocean
  • Modify repo and creds and then create a new pipeline using Blue Ocean and the linked GitHub repo; configure the webhook; and create the 'dev' branch in the repo as well as a pull reqvest merging dev into Main
Part 4 (Bonus): Branch speific Pipeline in Blue Ocean
  • The code build and push to Docker Hub should occur on the dev branch

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

Jenkins Mastery
3 questions

Jenkins Mastery

WellWishersNephrite avatar
WellWishersNephrite
Jenkins Build Tools Quiz
3 questions

Jenkins Build Tools Quiz

IntuitiveMountain avatar
IntuitiveMountain
DevOps, CI/CD with Python and Powershell
31 questions
Use Quizgecko on...
Browser
Browser