首页 > 解决方案 > 当 jenkins.war 未运行时,Jenkins 未运行

问题描述

我正在尝试为我正在从事的 selenium/maven 项目自动安排 Jenkins 工作。一切运行正常,自动调度仅在 .jar 文件运行时才有效(使用命令:)java -jar jenkins.war --httpPort=8089。但是一旦我退出命令提示符和 Jenkins 服务器,它就根本不会运行。我假设它应该运行,无论是否连接以及计算机正在登录或注销。

在我看来,当 jenkins.war 文件未启动并运行时,Jenkins Autoscheduling 不起作用。

我在这里错过了什么吗?

标签: javaseleniummavenjenkinsautomation

解决方案


如果文件没有被执行,整个jenkins过程就不会运行。.war问题是你如何运行 Jenkins。

大量文档如何运行它。但是,我最终通过拥有一个服务文件在systemd启用的操作系统(linux)上运行::system.d/usr/lib/systemd/system/jenkins.service

[Unit]
Description=Jenkins
Documentation=https://wiki.jenkins.io/display/JENKINS/Use+Jenkins
After=network.target
Requires=network.target

[Service]
Type=simple
EnvironmentFile=/etc/default/jenkins
ExecStart=/home/jenkins/jdk/jdk1.8.0_121/bin/java -Xmx2048m -Xms1024m -DJENKINS_HOME=/home/jenkins -jar /home/jenkins/jenkins.war --javaHome=/home/jenkins/jdk/jdk1.8.0_121 --httpPort=8080 --webroot=/var/cache/jenkins/war --ajp13Port=-1 --debug=5 --handlerCountMax=100 --handlerCountMaxIdle=20
# Restart=always
# RestartSec=120
User=jenkins

[Install]
WantedBy=multi-user.target

/etc/default/jenkins::

# Managed manually
JENKINS_HOME="/home/jenkins"
#JENKINS_LOGFILE="/home/jenkins/jenkins.log"

# TODO: manage JAVA_HOME through java-alternatives
JAVA_HOME="/home/jenkins/jdk/jdk1.8.0_121"
JAVA_OPTIONS="-Xmx2048m -Xms1024m"

# Web Configuration
HTTP_WEB_ROOT="/var/cache/jenkins/war"
HTTP_PORT="8080"
HTTP_LISTEN_ADDRESS="0.0.0.0"

# Jenkins Configurations
#   more: https://wiki.jenkins.io/display/JENKINS/Starting+and+Accessing+Jenkins
JENKINS_ARGS="--ajp13Port=-1 --debug=5 --handlerCountMax=100 --handlerCountMaxIdle=20"
$ systemctl status jenkins
● jenkins.service - Jenkins
   Loaded: loaded (/usr/lib/systemd/system/jenkins.service; linked; vendor preset: disabled)
   Active: active (running) since Wed 2021-03-31 10:08:36 EDT; 1 weeks 1 days ago
     Docs: https://wiki.jenkins.io/display/JENKINS/Use+Jenkins
 Main PID: 27219 (java)
    Tasks: 70 (limit: 512)
   CGroup: /system.slice/jenkins.service
           └─27219 /home/jenkins/jdk/jdk1.8.0_121/bin/java -Xmx2048m -Xms1024m

并通过 Apache HTTP Server 发布它,通过 ProxyPath :

$ systemctl status apache
● apache2.service - The Apache Webserver
   Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-02-02 12:34:05 EST; 2 months 4 days ago
  Process: 30426 ExecReload=/usr/sbin/start_apache2 -DSYSTEMD -DFOREGROUND -k graceful (code=exited, status=0/SUCCESS)
 Main PID: 18524 (httpd-prefork)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
    Tasks: 11
   CGroup: /system.slice/apache2.service

使用 Apache HTTP 虚拟主机配置:

<IfDefine SSL>
<IfDefine !NOSSL>

##
## SSL Virtual Host Context
##

<VirtualHost _default_:443>

  ProxyPass         /  http://localhost:8080/ nocanon
  ProxyPassReverse  /  http://localhost:8080/

  # ProxyRequests     Off
  ProxyPreserveHost On
  AllowEncodedSlashes NoDecode

  <Proxy http://localhost:8080/*>
    Require all granted
  </Proxy>

  # ProxyPassMatch  ^/(?\!.well-known)  http://localhost:8080 nocanon

  ErrorLog /var/log/apache2/error_log
  TransferLog /var/log/apache2/access_log

  #   SSL Engine Switch:
  #   Enable/Disable SSL for this virtual host.
  SSLEngine on

  #   You can use per vhost certificates if SNI is supported.
  SSLCertificateFile /etc/apache2/ssl.crt/<your-server>.com.crt
  SSLCertificateKeyFile /etc/apache2/ssl.key/<your-server>.com.key

  CustomLog /var/log/apache2/ssl_request_log   ssl_combined

</VirtualHost>

</IfDefine>
</IfDefine>

相同的配置设置,但通过 NGINX:Jenkins reverse-proxy configuration nginx

通过这种方式,您可以管理您的 jenkins 服务器(启动/停止)并管理 TLS (SSL) 通信:

systemctl status jenkins nginx

如果你通过 Docker 运行 Jenkins,你不需要在 Jenkins 前面公开另一个 WebServer(例如 Apache/NGINX),你不会公开 Jenkins Docker 容器,但你可能有一个 Kubernetes/(A)LB在前。不建议公开曝光 Jenkins。

WebServer 让您可以灵活地在 Jenkins 前使用缓存或 CDN,尤其是在您使用Publish artifacts功能的情况下。


推荐阅读