DEV Community

Cover image for 🌟Install Jenkins in Windows Subsystem for Linux (WSL2)
David
David

Posted on

🌟Install Jenkins in Windows Subsystem for Linux (WSL2)

Jenkins

Jenkins is one of the most popular tools DevOps tools, originally designed with one purpose in mind: be a great build automation server. It’s free and open-source, built for developers, and has lots and lots of plugins that you can configure to build anything.

Although Jenkins can be deployed to lots of public clouds like AWS, GCP or Azure, running a local Jenkins server still has its own advantages and values. Speeds and easy for experimentation are just two of the most important ones.

Windows Subsystem for Linux

The Windows Subsystem for Linux (WSL) lets developers run a GNU/Linux environment -- including most command-line tools, utilities, and applications -- directly on Windows, unmodified, without the overhead of a traditional virtual machine or dual-boot setup.

WSL 2 is a new version of the Windows Subsystem for Linux architecture that powers the Windows Subsystem for Linux to run ELF64 Linux binaries on Windows. Its primary goals are to increase file system performance, as well as adding full system call compatibility.

Install WSL2 on Windows

For the full instructions to install WSL2 on windows, refer to this link or this one

Mix together: Install Jenkins in Windows Subsystem for Linux

This blog will focus on putting all the nice stuffs together: Windows + Ubuntu + Jenkins.

image

Open a terminal in Windows

Open a new Ubuntu terminal (I am using Windows Terminal, but you can use whatever terminal tools like blow excellent candidates)

image

Update Ubuntu in WSL2

Below here are the quick scripts for updating Ubuntu in WSL2:

sudo -s
apt-get update
apt-get -y install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
apt-get update
Enter fullscreen mode Exit fullscreen mode

Install Java and Jenkins in WSL2

sudo apt install openjdk-8-jdk           # choose this or next line
sudo apt install openjdk-11-jre-headless # or Install Java 11 JDK/JRE
sudo apt install Jenkins
Enter fullscreen mode Exit fullscreen mode

You will get an error like below:

image

To solve this, run the below script:

wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add
sudo bash -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt update
sudo apt-get install jenkins
Enter fullscreen mode Exit fullscreen mode

With this, ~ 68MB Jenkins package will be downloaded, it will take a while depending on the internet speeds.

Update Firewall to enable Jenkins service

sudo ufw enable
sudo ufw allow 8080 # whatever port number you like
Enter fullscreen mode Exit fullscreen mode

Check the status of your port:

sudo ufw status
Enter fullscreen mode Exit fullscreen mode

Run Jenkins server

sudo service jenkins start
Enter fullscreen mode Exit fullscreen mode

Install Jenkins from a browser

Navigate to your host browser, and type:

http://localhost:8080/
Enter fullscreen mode Exit fullscreen mode

You will see the screen as below:

image

where you will be prompted to provide an initial password to unlock Jenkins.

Follow up the screen instructions and in the terminal, type below:

sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Enter fullscreen mode Exit fullscreen mode
  • Copy the password you retrieved to clipboard
    image

  • Return to the host browser window, and paste the password therein

  • Click "Continue" button!

Follow the screen instructions to create an account. Hooray!

image

Top comments (5)

Collapse
 
francisvila profile image
Francis Vila

Everything works up to sudo ufw enable .
This triggers an error starting with

ERROR: problem running ufw-init
modprobe: ERROR: ../libkmod/libkmod.c:586 kmod_search_moddep() could not open moddep file '/lib/modules/4.4.0-19041-Microsoft/modules.dep.bin'
Enter fullscreen mode Exit fullscreen mode

Looking up the errors does not give encouraging results. It appears ufw does not function with WSL.
This link: askubuntu.com/questions/1100739/i-... even concludes (about ufw on WSL) that "Some tools are really not portable to different platforms".

I read a stackoverflow post (stackoverflow.com/questions/660185... ) saying "Just let the Windows Firewall do its job if you are concerned about external access to the Nginx. " But no clues as to how to do this.

I'm using Ubuntu 18.04

Collapse
 
alogan5201 profile image
alogan5201

I had the same issue and this resolved it:
Run:
sudo nano /usr/lib/python3/dist-packages/ufw/util.py

Replace under_ssh function with

def under_ssh(pid=None):
'''Try to determine if we are being run from an ssh session'''
if pid is None:
pid = str(os.getpid())

ppid = None
try:
    name = "/proc/%s/stat" % pid
    ppid = open(name).readlines()[0].split(')')[1].split()[1]
except IOError:
    err_msg = _("Couldn't find parent pid for '%s'") % pid
    raise ValueError(err_msg)
except IndexError: # Add this block
    return False

if ppid == '1':
    return False

name = "/proc/%s/cmdline" % ppid
try:
    cmdline = open(name).readline().strip().split('\x00')
except IOError:
    return False

for i in cmdline:
    if re.search('sshd', i):
        return True

return under_ssh(ppid)
Enter fullscreen mode Exit fullscreen mode
Collapse
 
davidkou profile image
David

Thanks Chupavn!

Collapse
 
chupavn profile image
chupavn • Edited

Great! 👍

Collapse
 
felipecaparelli profile image
Felipe Caparelli

Excellent, saved the day! I've tried three other articles, but yours was the only one that really worked well on WSL-Ubuntu (Windows 10). Thanks!