DEVOPS UNIT 4
DEVOPS UNIT 4
Setting up a Jenkins build server involves a series of steps. Here's a general outline of
the process:
1. Install Java: Jenkins is built in Java, so you'll need to install Java Development Kit (JDK)
on your server. You can download the JDK from the Oracle website or use OpenJDK,
which is an open-source alternative.
2. Download and Install Jenkins: Visit the Jenkins website (https://www.jenkins.io/) and
download the latest stable version of Jenkins. Follow the installation instructions specific
to your operating system. Jenkins is available for Windows, macOS, and Linux.
3. Start Jenkins: Once installed, you can start Jenkins by running the Jenkins service or
using the command-line interface. Jenkins usually runs on port 8080 by default.
4. Access Jenkins: Open a web browser and enter the address http://localhost:8080
(replace "localhost" with the actual server IP if Jenkins is installed on a remote machine).
You will be prompted to unlock Jenkins by entering an initial admin password. Retrieve
the password from the Jenkins installation directory or follow the on-screen instructions.
5. Customize Jenkins: After unlocking Jenkins, you can install plugins and customize its
configuration. Select the plugins you need for your build environment, such as Git,
Maven, or Docker, during the initial setup. You can also install additional plugins later
from the Jenkins web interface.
6. Create an Admin User: Set up an administrative user account for Jenkins. Provide a
username, password, and other relevant details.
7. Configure Jenkins: Configure the system settings, such as the URL for Jenkins, email
notifications, and any necessary security settings. You can access the configuration
options through the "Manage Jenkins" section of the Jenkins web interface.
8. Create a Build Job: To create a build job, go to the Jenkins dashboard and click on
"New Item." Enter a name for the job and select the appropriate job type (e.g., Freestyle
project, Pipeline). Configure the build steps, such as pulling code from a version control
system, building the project, running tests, and deploying the application.
9. Save and Run the Build Job: Save the job configuration and click on "Build Now" to
initiate a build. Jenkins will execute the defined steps and provide real-time logs of the
build process.
10. Set Up Build Triggers: Configure build triggers to automatically start a build when
specific events occur, such as code commits or a scheduled time. You can define triggers
in the job configuration or use plugins like the GitHub plugin or the Poll SCM plugin.
11. Monitor and Manage Builds: Jenkins provides various tools to monitor and manage
builds. You can view the build history, check build statuses, and review the console
output for each build job. Jenkins also offers options for managing build queues, agents,
and distributed builds.
These steps provide a general overview of setting up a basic Jenkins build server.
Depending on your specific requirements and environment, you may need to configure
additional settings or plugins. The Jenkins documentation (https://www.jenkins.io/doc/)
is a valuable resource for detailed instructions and advanced configurations.
PLUGINS
Jenkins has a vast collection of plugins that extend its functionality and integrate with
various tools and technologies. Here are some popular Jenkins plugins across different
categories:
• Git Plugin: Integrates Jenkins with Git for source code management.
• Subversion Plugin: Provides support for Subversion (SVN) repositories.
• Bitbucket Plugin: Enables integration with Atlassian Bitbucket for version control.
Build Tools:
• Maven Integration Plugin: Integrates Jenkins with Apache Maven for building Java
projects.
• Gradle Plugin: Adds support for Gradle build tool in Jenkins.
• JUnit Plugin: Publishes JUnit test results in Jenkins and generates reports.
• Jacoco Plugin: Integrates Jenkins with JaCoCo for code coverage reports.
• Selenium Plugin: Integrates Jenkins with Selenium for running automated web tests.
• Docker Plugin: Provides integration with Docker to build, publish, and run Docker
containers.
• Kubernetes Plugin: Enables deploying applications to Kubernetes clusters from Jenkins.
• AWS Elastic Beanstalk Plugin: Integrates Jenkins with AWS Elastic Beanstalk for
application deployment.
• Email Extension Plugin: Allows sending email notifications based on build status.
• Slack Notification Plugin: Sends build notifications and updates to Slack channels.
• HTML Publisher Plugin: Publishes HTML reports and artifacts in Jenkins.
• Prometheus Plugin: Integrates Jenkins with Prometheus for collecting and monitoring
metrics.
• SonarQube Plugin: Integrates Jenkins with SonarQube for code quality analysis.
These are just a few examples, and there are many more plugins available for Jenkins,
covering a wide range of use cases. You can explore and install plugins directly from the
Jenkins web interface by navigating to "Manage Jenkins" > "Manage Plugins."
BUILD TRIGGERS
1. Poll SCM: With this trigger, Jenkins periodically checks the configured source code
repository for changes. If there are new commits, Jenkins starts a build. You can specify
the polling schedule using cron syntax.
2. Schedule: This trigger allows you to schedule builds at specific times using cron
syntax. For example, you can schedule a nightly build or a weekly deployment.
4. Build after other projects are built: This trigger enables you to set up dependencies
between Jenkins projects. When one project finishes building, it triggers the build of
another project. This is useful for creating build pipelines and managing project
dependencies.
5. Trigger builds remotely (e.g., via API): Jenkins provides a remote API that allows
external systems to trigger builds programmatically. You can use this trigger to initiate
builds from external scripts, tools, or other automation systems.
6. SCM triggering (e.g., based on specific files or paths): Using this trigger, you can
configure Jenkins to start a build when specific files or paths in the source code
repository are modified. This is useful when you want to trigger builds based on
changes in particular files or directories.
7. Pull Request (PR) events: If you're using a source code repository that supports pull
requests (e.g., GitHub, Bitbucket), Jenkins can be configured to trigger builds when pull
requests are opened, updated, or merged. This allows you to automatically build and
test changes introduced through pull requests.
8. External events and plugins: Jenkins has various plugins that provide integration
with external systems, such as issue trackers, test automation tools, and continuous
integration platforms. These plugins can trigger Jenkins builds based on specific events
or conditions in those systems.
To configure build triggers in Jenkins, navigate to the configuration page of your Jenkins
project (job) and look for the "Build Triggers" section. There you can select the desired
trigger(s) and configure the associated settings based on your requirements.
Keep in mind that the availability of specific build triggers may depend on the plugins
you have installed and the version of Jenkins you are using.
In Jenkins, build phases define the sequence of actions and steps performed during a build. Each
build phase represents a specific stage in the build process. Here are the common build phases
in Jenkins:
1. Preparation: In this phase, Jenkins prepares the environment for the build. It typically
involves actions such as checking out the source code from a version control system, fetching
dependencies, or initializing any required resources.
2. Build: The build phase is where the main compilation, testing, and packaging of the project
take place. It includes tasks like compiling source code, running unit tests, and generating build
artifacts.
3. Test: In this phase, Jenkins executes various types of tests to validate the build. It can involve
unit tests, integration tests, functional tests, performance tests, or any other test suites defined
for the project. Test results are typically collected and reported during this phase.
4. Deployment: The deployment phase involves deploying the built artifacts to the target
environment. It may include tasks like copying files to a server, publishing artifacts to a
repository, or deploying applications to a cloud platform or production environment.
5. Post-Build Actions: After the primary build and deployment steps, Jenkins allows you to
perform additional actions or processes. These actions are typically related to reporting,
notifications, archiving build artifacts, or triggering downstream jobs. Examples include sending
build notifications, generating reports, or triggering a separate job for integration or acceptance
testing.
These build phases can be configured and customized based on the specific requirements of
your project. Jenkins provides flexibility in defining the sequence and actions within each phase.
You can use various plugins, scripting languages (e.g., Groovy, Shell), and integration with
external tools to extend and customize the build phases according to your needs.
The configuration of build phases in Jenkins is typically done through the job configuration
page. Depending on the job type (e.g., Freestyle project, Pipeline), you can define the build
phases in the appropriate section of the configuration interface.
In Jenkins, slaves (also known as agents or nodes) are additional worker machines that offload the build and execution tasks
from the Jenkins master. Slaves provide distributed build capabilities, allowing Jenkins to scale and handle multiple builds concurrently.
Here's some information about Jenkins slaves:
1. Purpose of Slaves: Jenkins slaves are used to execute build jobs on remote machines, separate from the Jenkins master. They help
distribute the workload and enable parallel execution of builds, thereby increasing the overall capacity and efficiency of Jenkins.
• Permanent Slaves: These slaves are permanently connected to the Jenkins master and are always available for executing build jobs.
Permanent slaves can be physical machines or virtual machines.
• Cloud-based Slaves: Cloud-based slaves are dynamically provisioned and released as needed. Jenkins can utilize cloud platforms like
Amazon EC2, Google Cloud, or Microsoft Azure to automatically create and destroy slaves based on demand. Cloud-based slaves are ideal for
handling variable or bursty workloads.
3. Setting up Slaves: To set up a slave in Jenkins, you typically need to perform the following steps:
• Install the Jenkins agent software on the machine that will act as the slave.
• Connect the slave machine to the Jenkins master by establishing network connectivity.
• Register the slave with the Jenkins master by providing necessary configuration details such as the slave name, connection information, and
any specific labels or tags to identify the slave's capabilities or characteristics.
4. Slave Configuration: In the Jenkins web interface, you can configure and manage slaves by navigating to "Manage Jenkins" > "Manage
Nodes and Clouds." From there, you can add new slaves, configure their connection details, specify labels or tags for identifying capabilities,
and set the number of concurrent builds allowed on each slave.
5. Node/Slave Selection: When configuring a build job, you can specify whether it should run on the Jenkins master or a specific slave. You
can assign a job to a slave based on labels or use Jenkins' built-in selection algorithms to choose an appropriate slave based on available
resources and build requirements.
6. Monitoring and Scaling: Jenkins provides monitoring and management capabilities for slaves. You can view the status of connected
slaves, monitor their resource utilization, and easily scale the number of slave instances as needed.