简体   繁体   English

Jenkins CLI 连接被拒绝

[英]Jenkins CLI connection refused

When executing执行时

java -jar jenkins-cli.jar -s https://jenkins_url help

I'm getting connection refused for some reason.由于某种原因,我的连接被拒绝。 Jenkins version is 1580.3, user has the permissions on Jenkins server, cli jar is up-to-date and ssh public key is configured properly. Jenkins 版本为 1580.3,用户在 Jenkins 服务器上有权限,cli jar 是最新的,ssh 公钥配置正确。 Any idea what might be causing this?知道是什么原因造成的吗? Here's the stack trace if it will help:如果有帮助,这是堆栈跟踪:

Exception in thread "main" java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at hudson.cli.CLI.connectViaCliPort(CLI.java:203)
at hudson.cli.CLI.<init>(CLI.java:126)
at hudson.cli.CLIConnectionFactory.connect(CLIConnectionFactory.java:72)
at hudson.cli.CLI._main(CLI.java:466)
at hudson.cli.CLI.main(CLI.java:382)
Suppressed: java.io.EOFException: unexpected stream termination
at hudson.remoting.ChannelBuilder.negotiate(ChannelBuilder.java:331)
at hudson.remoting.Channel.<init>(Channel.java:421)
at hudson.remoting.Channel.<init>(Channel.java:400)
at hudson.remoting.Channel.<init>(Channel.java:396)
at hudson.remoting.Channel.<init>(Channel.java:385)
at hudson.remoting.Channel.<init>(Channel.java:377)
at hudson.remoting.Channel.<init>(Channel.java:353)
at hudson.cli.CLI.connectViaHttp(CLI.java:157)
at hudson.cli.CLI.<init>(CLI.java:130)
... 3 more

If the connection is refused, perhaps the CLI is disabled, but more likely there's a firewall or network issue.如果连接被拒绝,则 CLI 可能被禁用,但更有可能是防火墙或网络问题。

Each successful HTTP request to Jenkins responds with the CLI port as an HTTP header, so you can quickly check whether it's enabled:对 Jenkins 的每个成功 HTTP 请求都会使用 CLI 端口作为 HTTP 标头进行响应,因此您可以快速检查它是否已启用:

curl -sI http://jenkins/ | grep CLI

Alternatively, as documented on the wiki , you can check whether the TCP port is enabled.或者,如wiki 上所述,您可以检查是否启用了 TCP 端口。 Look for "TCP port for JNLP slave agents" at http://jenkins/configureSecurity/http://jenkins/configureSecurity/查找“JNLP 从属代理的 TCP 端口”

However, since your stacktrace indicates that the CLI client is trying to establish a connection to a particular port, it suggests that the CLI is enabled, and Jenkins is advertising that port number in its HTTP responses.但是,由于您的堆栈跟踪表明 CLI 客户端正在尝试与特定端口建立连接,这表明 CLI 已启用,并且 Jenkins 在其 HTTP 响应中通告该端口号。

So you could try to connect to that port manually, to check whether it's open:因此,您可以尝试手动连接到该端口,以检查它是否已打开:

telnet jenkins <cli-port>

If you also see "Connection refused" here, then you know that your Jenkins and CLI client setup seem to be ok, but you have a network issue.如果您在此处还看到“连接被拒绝”,那么您就知道您的 Jenkins 和 CLI 客户端设置似乎没问题,但是您遇到了网络问题。 In which case, check that the firewall on the Jenkins server allows incoming connections on that CLI port.在这种情况下,请检查 Jenkins 服务器上的防火墙是否允许该 CLI 端口上的传入连接。

To make firewall configuration easier, you can switch from a random port to a fixed port in the "configure security" page mentioned above.为了让防火墙配置更简单,您可以在上面提到的“配置安全”页面中从随机端口切换到固定端口。

I had this issue on Ubuntu 16.04.我在 Ubuntu 16.04 上遇到了这个问题。

Note : this error happened to me well after setting up and having ran successful build jobs before.注意:在设置并运行成功的构建作业之后,这个错误发生在我身上。 This happened to me after running a particularly heavy build job.在运行了特别繁重的构建工作后,这发生在我身上。 So my fix might work assuming that the error isn't a firewall issue.因此,假设错误不是防火墙问题,我的修复程序可能会起作用。

First, I tried to do a safe restart through the commandline using the jenkins-cli.jar tool:首先,我尝试使用jenkins-cli.jar工具通过命令行进行安全重启:

java -jar jenkins-cli.jar -s http://localhost:8080 -auth <username>:<password> safe-restart

but also got the same Connection refused error message.但也得到了相同的Connection refused错误消息。

So as a last resort I tried restarting the Jenkins service on the server like so:所以作为最后的手段,我尝试重新启动服务器上的 Jenkins 服务,如下所示:

sudo systemctl restart jenkins

and that fixed it.并修复了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM