在 WSL 上安装 Jenkins 失败

在 WSL 上安装 Jenkins 失败

我正在尝试在 WSL(Windows 10 上的 ubuntu)上安装 Jenkins,但不知何故失败并且无法获取运行状态。以下是安装命令及其输出:

user@machine:~$ sudo apt install jenkins
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
daemon
The following NEW packages will be installed:
daemon jenkins
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 77.2 MB of archives.
After this operation, 77.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://archive.ubuntu.com/ubuntu bionic/universe amd64 daemon amd64 0.6.4-1build1 [99.5 kB]
Get:2 http://pkg.jenkins.io/debian-stable binary/ jenkins 2.164.1 [77.1 MB]
Fetched 77.2 MB in 40s (1923 kB/s)
Selecting previously unselected package daemon.
(Reading database ... 70496 files and directories currently installed.)
Preparing to unpack .../daemon_0.6.4-1build1_amd64.deb ...
Unpacking daemon (0.6.4-1build1) ...
Selecting previously unselected package jenkins.
Preparing to unpack .../jenkins_2.164.1_all.deb ...
Unpacking jenkins (2.164.1) ...
Processing triggers for ureadahead (0.100.0-20) ...
Processing triggers for systemd (237-3ubuntu10.17) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Setting up daemon (0.6.4-1build1) ...
Setting up jenkins (2.164.1) ...
invoke-rc.d: could not determine current runlevel
Processing triggers for systemd (237-3ubuntu10.17) ...
Processing triggers for ureadahead (0.100.0-20) ...

to check the status I run the following command without success:
user@machine:~$ systemctl status jenkins
System has not been booted with systemd as init system (PID 1). Can't operate. 

有任何想法吗 ?

答案1

要在 WSL 中安装并运行 Jenkins,请按照以下步骤操作:

  • 安装 JDK 和 JRE: apt install default-jdk default-jre

  • 导入 GPG 密钥: wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -

  • 添加 Jenkins 存储库: sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'

  • 更新并安装: apt update; apt install jenkins

在写这个答案的时候,WSL 确实不支持systemd初始化。因此,可以使用 SysVinit 脚本作为替代方案。运行 sudo /etc/init.d/jenkins start命令以将 Jenkins 启动为后台守护程序。对于个人配置,请在/etc/default/jenkins文件中添加参数。但由于与上一个原因相同,因此不会有 pidfile /var/run/jenkins/jenkins.pid。在任何 Web 浏览器中打开以检查 Jenkins 安装127.0.0.1:8080

进一步阅读:

答案2

使用

sudo service jenkins status

相关内容