GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — DevOpsProject/lab-8.2 at master · manikabedi/DevOpsProject

Expand file tree

/

lab-8.2

/
Copy path

Directory actions

More options

More options

Directory actions

More options

More options

Latest commit

 

History

History
History
/

lab-8.2

/
Copy path

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
git
git
 
 
Dockerfile
Dockerfile
 
 
README.md
README.md
 
 

README.md

Outline

Exercise 8.2 Jenkins and Git

In this exercise we will integrated Jenkins ad Git in Docker containers.

Step 1

Start the Google Compute Engine virtual machine and connect to it using SSH.

Check that the firewall allows traffice on port 8080. It should have been set up in an earlier lesson.

Delete SSH hosts to prevent problems later.
rm -r ~/.ssh/known_hosts

Change to the exercise directory. cd
cd devops-lesson-8/lab-8.2

Create a directory for Jenkins data.
mkdir jenkins
chmod 777 jenkins

Step 2

Get a Jenkins image from DockerHub.
docker pull jenkins

Start jenkins.
docker run -d --name jenkins -p 8080:8080 -p 50000:50000 -v $PWD/jenkins:/var/jenkins_home/ jenkins

Wait until jenkins is up and running. Use:
docker logs jenkins

Step 3

We need to ensure that we can connect from Jenkins to Git via SSH.
First run an interactive jenkins container and create SSH keys.
docker run -it --rm -v $PWD/jenkins:/var/jenkins_home jenkins /bin/sh
Generate SSH keys.
ssh-keygen -t rsa
Exit the container with control-D.

Copy the public keys for the student and jenkins users.
sudo cat ~/.ssh/id_rsa.pub jenkins/.ssh/id_rsa.pub > git/authorized_keys

Build a Git image.
docker build -t git git

Start a Git container.
docker run -d -p 2022:22 --name git git
Find its IP address and make a note of it.
docker inspect git

Now run a Jenkins container again and verify that you can connect.
docker run -it --rm -v $PWD/jenkins:/var/jenkins_home jenkins /bin/sh
Now connect to the Git container using SSH. You may have to change the last digit of the IP address to that of your container.
ssh [email protected]
Answer yes to accept the key.
You should connect OK.
Exit both containers with control-D control-D.

Clone the Git repository. Ignore the warning about the repository being empty.
git clone ssh://git@localhost:2022/home/git/project.git

Check in some data.
cd project
echo "First message" > readme.txt
git add readme.txt
git commit -m "First checkin"
git push

Step 4

You will need an admin password. Get the jenkins logs and scroll back to find the password. Copy it ready to paste later.
docker logs jenkins

Start a browser on your local machine and enter the URL x.x.x.x:8080 replacing x.x.x.x with the external IP address of your virtual machine.

You will see an Unlock Jenkins screen. Paste the admin password and hit Continue.

The next screen is Customize Jenkins. Hit Select plugins to install.

Select Source Code Management. Make sure that Git plugin is selected.

Select Install.

A Getting Started screen will be displayed and plugins will start downloading. This will take a few minutes.

You will next be asked to create an admin user. Fill in the form and select Save and Finish.

Jenkins is set up. Select Start using Jenkins.

Step 5

Select create new jobs.
Enter the name DevOps.
Select Freestyle project.
Hit OK.

Scroll down to Source Code Management.
Select Git.
Enter the following URL possibly changing the last digit of the IP to your Git IP.
ssh://[email protected]/home/git/project.git
Hit Apply. The URL should be accepted. If there is an error in red check the URL.
Hit Save.

You will be taken to the Project DevOps page.

Select Build Now. The project should build.
Click on the #1 at the bottom of the page. It will show the build and the date and time.
Select Console Output.
You should see the details of the build.

Step 6

Stop the servers.
docker stop jenkins git

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.