0% found this document useful (0 votes)
60 views

Ex 4 Devops

1. Jenkins is an open source automation server that can be used to automate tasks like building, testing, and deploying software projects. It supports continuous integration by automatically building code changes and running tests. 2. Jenkins can be installed via a Docker container or by running the .war file directly. After installation, Jenkins is configured by creating users and installing plugins. 3. In Jenkins, projects or jobs are created to build software. A job can be configured to poll a git repository for changes or trigger on commits. It runs tasks like compiling code and running tests. 4. Pipelines in Jenkins help define a repeatable workflow for a project involving multiple stages and tasks. Pipelines are defined in

Uploaded by

Shivam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

Ex 4 Devops

1. Jenkins is an open source automation server that can be used to automate tasks like building, testing, and deploying software projects. It supports continuous integration by automatically building code changes and running tests. 2. Jenkins can be installed via a Docker container or by running the .war file directly. After installation, Jenkins is configured by creating users and installing plugins. 3. In Jenkins, projects or jobs are created to build software. A job can be configured to poll a git repository for changes or trigger on commits. It runs tasks like compiling code and running tests. 4. Pipelines in Jenkins help define a repeatable workflow for a project involving multiple stages and tasks. Pipelines are defined in

Uploaded by

Shivam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

EXPERIMENT NO 4

Aim: To implement Jenkins programming.

Theory:
“Continuous Integration is a software development practice where members of a team
integrate their work frequently, usually each person integrates at least daily - leading to
multiple integrations per day. Each integration is verified by an automated build (including
test) to detect integration errors as quickly as possible.” In simple way, Continuous
integration (CI) is the practice of frequently building and testing each change done to your
code automatically. Jenkins is a self-contained, open source automation server which can be
used to automate all sorts of tasks related to building, testing, and delivering or deploying
software. Our first job will execute the shell commands. The freestyle project provides
enough options and features to build the complex jobs that you will need in your projects.

OUTPUT:
1. Installation in a Docker container
docker pull jenkins/jenkins:lts

# list images, jenkins should be available


docker images

docker ps will not show a running container, as we did not yet start it. Start an instance of Jenkins
with the following command:

docker run -p 8080:8080 -p 50000:50000 -v [werjenkinshome]:/var/jenkins_home jenkins/jenkins:lts

Replace [werjenkinshome] with a path fitting for we, e.g. /home/vogella/jenkins_home.

For example, on Windows:

docker run -u 0 -p 8082:8080 -p 50002:50000 -v //C/Users/Lars/jenkins:/var/jenkins_home jenkins/jenkins:lts

If we need other tools installed, we can create wer own Docker file with the necessary tooling
installed. For example the following creates a new image based on Jenkins with Maven installed.

 Create a new directory


 Create a file called Dockerfile with the following content:
FROM jenkins/jenkins:lts
# if we want to install via apt
USER root
RUN apt-get update && apt-get install -y maven
# drop back to the regular jenkins user - good practice
USER jenkins
 Create a new image with wer Dockerfile
docker build -t jenkins-maven .

Now we can start wer new image jenkins-maven-latest.

docker run -u 0 -p 8082:8080 -p 50002:50000 -v //C/Users/Lars/jenkins:/var/jenkins_home jenkins-maven:latest

All the configuration and jobs will be stores in wer user defined directory.

2. Using .war file to start Jenkins

Download the jenkins.war file.. From this file we can start Jenkins directly via the command line
with java -jar jenkins*.war.

If we start it locally, we find it running under the following URL: http://localhost:8080/

To run it in wer Tomcat server, put the .war file into the webapps directory. If we start Tomcat,
wer Jenkins installation will be available under

http://localhost:8080/jenkins

If the jenkins.war is deployed in wer webapps directory, but can not be started and the tomcat
manager says FAIL - Application at context path /jenkins could not be started, we may need to
grant the permissions for JENKINS_HOME.

sudo mkdir .jenkins

sudo

chown tomcat7:nogroup .jenkins

3. Configure Jenkins
After installation, open a browser and connect to it. The default port of Jenkins is :8080,
therefore on wer local machine we find it under the following URL:
http://localhost:8080/

We will need to copy the initial password from the file system of the server.

Afterwards we can select to install Plugins. Select the Install suggested Plugins to get a typical
configuration.

Create an admin user and press Save and Finish.

Select Manage Jenkins and then Configure Global Security. Select the Enable security flag. The
easiest way is to use Jenkins own user database. Create at least the user "Anonymous" with read
access. Also create entries for the users we want to add in the next step.
On the login page, select Create an account to create the users we just gave access.

Assign roles to users

If we want to create a role based authorization Strategy we first need to install the Role-based
Authorization Strategy Plugin. Go to Manage Jenkins Manage Plugins Available enter Role-
based Authorization Strategy in the filter box and select and install the Plugin. To see a list of
commonly used Plugins go to Plugin management.

Now go to Manage Jenkins Manage and Assign Roles Assign Roles to grant users additional
access rights.

Navigate to Manage Roles to define access restrictions in detail. Pattern is a regex value of the job
name. The following grants unregistered users read-only access to wer build jobs that start with
the L-, C-, I- or M- and only those.

Generate ssh key for Jenkins user

If we want to access a private Git repo, for example at GitHub, we need to generate an ssh key-
pair. Create a SSH key with the following command.

sudo -u jenkins ssh-keygen

The public key must be uploaded to the service we are using, e.g., GitHub.

Configure the default port of the Jenkins build server

The default port number can be changed in the config file at

sudo vim /etc/default/jenkins

Here we can set a different port number, e.g. HTTP_PORT=8082

Now we need to restart Jenkins with


service jenkins restart

4. Setting up a Jenkins job


The build of a project is handled via jobs in Jenkins. Select New Item. Afterwards, enter a name for the
job and select Freestyle project and press OK.

Enter a description for the job (project name) and configure how many builds should be retained and for
how long.

Configure how the source code can be retrieved. If we are for example using Git, enter the URL to the Git
repository. If the repository is not public, we may also need to configure the credentials.

Specify when and how wer build should be triggered. The following example polls the Git
repository every 15 min. It triggers a build, if something has changed in the repo.
To trigger a build after a commit on the Git repository, select GitHub hook trigger for GITScm
polling instead of Poll SCM.

Press Save to finish the job definition. Press Build Now on the job page to validate that the job
works as expected.
After a while the job should go to green or blue (depending on wer configuration), if successful.
Click on the job and afterwards on Console Output to see the log file. Here we can analyze the
build errors.
5. Build Pipelines
Jenkins pipelines help we align the build process of a project. This is done by specifying tasks
and the order in which they are executed. There are all kinds of possible tasks that a Jenkins
pipeline can do for we. For example, build assets, send an email on error, send the build artifacts
via SSH to wer application server, etc.
Jenkins allows to specify pipelines using a Jenkinsfile. This is just a textfile that contains the
necessary data for Jenkins to execute the pipeline.
Jenkins supports two different syntaxes.
1. Declarative (since Pipeline version 2.5)
2. Scripted
For this tutorial we will focus on the declarative approach.
The following example shows a pipeline with 2 stages:
pipeline {
agent any

stages {
stage('Build Assets') {
agent any
steps {
echo 'Building Assets...'
}
}
stage('Test') {
agent any
steps {
echo 'Testing stuff...'
}
}
}
}
The agent directive tells Jenkins to allocate a workspace and an executor for the pipeline. Without it, the
pipeline is not valid and therefore required.
Setup using the Blue Ocean Plugin
The above process can also be done using the Blue Ocean Jenkins Plugin.
To install the Plugin go to Manage Jenkins Manage Plugins Available and select the Blue
Ocean Plugin.
After the installation is finished we have an additional menu entry called Open Blue Ocean in
wer main Jenkins navigation.

Creating a new Pipeline


Click on New Pipeline to create a new Pipeline.

Select wer version control provider.


Depending on wer provider we will need to pass some kind of credentials.

The Blue Ocean application will provide a link to the GitHub page we need to visit. The necessary
permissions that Blue Ocean needs to operate are already selected. Add a description and click
on Generate Token at the bottom of the page.
Copy the generated token and paste it in the Blue Ocean mask.
Select the account the repository belongs to and select the repository.
Adding steps to wer Pipeline
In the next screen we will see a visual representation of wer Pipeline. Here we can add or remove steps.
To create a new step click on + in the canvas. A menu will open on the right that lets we specify
a name and what steps we want to perform.

After we have finished editing the Pipeline Blue Ocean will offer we to commit the newly
created pipeline to wer repository.
Under the hood Blue Ocean only created a valid Jenkinsfile to be used by Jenkins.
After committing Jenkins will build the project using the newly modified Pipelines.
6. Restart wer Jenkins

After installing Plugins we will need to restart Jenkins. We can do so by adding restart as URL
parameter,

or with the following command:

service jenkins restart

CONCLUSION:
Here, we got to learn about the Jenkins Programming and how to install and configure it.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy