CND - Jenkins - Introduction - Unit-III-II
CND - Jenkins - Introduction - Unit-III-II
Introduction
5. Unlock Jenkins
Administrator password while accessing Jenkins for the first time. To retrieve the password:
1.Navigate to the C:\Program Files (x86)\Jenkins\secrets folder.
2.Open the initialAdminPassword file with a text editor and copy the password.
3.Paste the password into the Jenkins web interface.
6. Install Plugins
After unlocking Jenkins, you will be prompted to install plugins. Jenkins offers two options:
•Install suggested plugins: Recommended for new users.
•Select plugins to install: Customize the plugins based on your needs.
You can add or remove plugins later via Manage Jenkins > Manage Plugins.
7. Create Admin User
• Once plugins are installed, Jenkins will ask you to set up your admin user:
• Enter a username, password, and other details. Save the settings
Install & Configure Jenkins
8. Configure Jenkins
Step 1: Set Java Path (Optional but Recommended)
Ensure that Jenkins uses the correct Java version:
1. Go to Manage Jenkins > Global Tool Configuration.
2. In the JDK section, add a new JDK installation and provide the path to your Java
installation.
Step 2: Configure Jenkins Home Directory (Optional)
By default, Jenkins stores its data in C:\Program Files (x86)\Jenkins.
You can change the home directory if needed by editing the Jenkins.xml configuration file
in the Jenkins installation folder.
1. Open C:\Program Files (x86)\Jenkins\Jenkins.xml in a text editor.
2. Locate the following section:
<env name="JENKINS_HOME" value="%BASE%/Jenkins"/>
3. Change the value to the desired directory and restart the Jenkins service.
Step 3 − The following screen will come up in which you can specify the details of the job.
Creating a Jenkins Job
Creating a Jenkins Job
Step 4 − We need to specify the location of files which need to be built. In this
example, we will assume that a local Git repository (E:\Program) has been setup
which contains a ‘HelloWorld.java’ file. Hence scroll down and click on the Git
option and enter the URL of the local Git repository.
Note − If the repository hosted on GitHub, you can also enter the URL of that
repository here. In addition to this, you would need to click on the Add button for
the credentials to add a user name and password to the GitHub repository so that
the code can be picked up from the remote repository.
Step 5 − Now go to the Build section and click on Add build step → Execute
Windows batch command
Step 6 − In the command window, enter the following commands and then click
on the Save button.
Javac HelloWorld.java
Java HelloWorld
Creating a Jenkins Job
Creating a Jenkins Job
Step 7 − Once saved, you can click on the ‘Build Now’ option to see if you have
successfully defined the job.
Step 8 − Once the build is scheduled, it will run. The Build history section shows
that a build is in progress.
Step 9 − Once the build is completed, a status of the build will show if the build was
successful or not. In our case, the following build has been executed successfully.
Click on the #1 in the Build history to bring up the details of the build.
Step 10 − Click on the ‘Console Output’ link to see the details of the build
Apart from the steps shown above there are just so many ways to create a build
job, the options available are many, which what makes Jenkins such a fantastic
continuous deployment tool.
Creating a Jenkins Job
Creating a Jenkins Job
Creating a Jenkins Job
Introduction to Plugins
Plugins are small, independent programs that can improve and extend the functionality of
Jenkins CI/CD.
There are over 1,900+ Jenkins plugins available right now and it keeps on increasing
month by month. So there is a plugin to suit almost every need in software development.
We can Install the Jenkins Plugins from the Jenkins Update Centre. It is a centralized
repository of Jenkins plugins which is being maintained by the Jenkins community.
Step 3: Click on the Manage Plugins, and then search for the plugin you want to install from
the Jenkins Update Centre.
How to Install Jenkins Plugins?
Step 3: After your Jenkins Plugin selection >> Click the Install button to confirm the
installation. (Note: You can select multiple plugins at a time.)
Step 4: After installing the Jenkins plugins, you need to restart Jenkins for the changes to
take effect. Click on the logout button in the top right corner of the page to restart the Jenkins.
That’s it! now you can login to Jenkins servers and verify your installed Plugins from Manage
Plugins >> Installed Plugins.
How to Manage Jenkins Plugins?
Update Jenkins Plugins:
Step 1: Open your Jenkins installed web browser and navigate to the Jenkins URL
(http://localhost:<your configured port>).
Step 2: Access Jenkins web interface Dashboard >> Go to Manage Jenkins > Click on the
Manage Plugins >> Click on Updates >> search or select the Plugin that you want to
update then click the Update Now button. Jenkins will check for updates for installed plugin,
and then install any updates that are available.
CI/CD pipeline as the backbone of the DevOps approach. This Pipeline is responsible for
building codes, running tests, and deploying new software versions.
Defining Pipeline-as-Code:
•The code that defines a pipeline is written inside a text file, known as the Jenkinsfile.
•The pipeline-as-code model recommends committing the Jenkinsfile to the project
source code repository. This way, a pipeline is modified, reviewed, and versioned like
the rest of the source code.
•It’s also possible to create a pipeline and provide its specification using Jenkins’ web
UI
Jenkins Pipeline-as-Code
pipeline {
agent any
stages {
stage('Build') {
steps {
// compile code
// if successful, move build artifacts to the desired location
}
}
stage('Test') {
steps {
// check if artifacts are present in the correct location
// load test data into the database
// execute the test case
// continue only if tests passed
}
}uio
stage('Deploy') {
steps {
// Fetch tested code and deploy it to production
}
}
}
}