Jenkins 2.7.4安装在RedHat服务器中,Linux Slaves通过选择“通过执行命令在主服务器上启动代理”选项进行配置.我们创建了一个Shell脚本,它在Jenkins版本2.7.4中运行良好.
现在我们将Jenkins升级到2.121.1.现在,同一个脚本会抛出错误
<===[JENKINS REMOTING CAPACITY]===>Exception in thread “main”
java.io.StreamCorruptedException: invalid stream header: 099EACED at
java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:808)
at java.io.ObjectInputStream.(ObjectInputStream.java:301) at
hudson.remoting.ObjectInputStreamEx.(ObjectInputStreamEx.java:48)
at
hudson.remoting.ChannelBuilder.makeTransport(ChannelBuilder.java:478)
at hudson.remoting.ChannelBuilder.negotiate(ChannelBuilder.java:433)
at hudson.remoting.ChannelBuilder.build(ChannelBuilder.java:354) at
hudson.remoting.Launcher.main(Launcher.java:743) at
hudson.remoting.Launcher.runWithStdinStdout(Launcher.java:691) at
hudson.remoting.Launcher.run(Launcher.java:373) at
hudson.remoting.Launcher.main(Launcher.java:283) ERROR: Connection
terminated ERROR: Unexpected error in launching an agent. This is
probably a bug in Jenkins java.io.IOException: Unexpected EOF at
hudson.remoting.ChunkedInputStream.readUntilBreak(ChunkedInputStream.java:99)
at
hudson.remoting.ChunkedCommandTransport.readBlock(ChunkedCommandTransport.java:39)
at
hudson.remoting.AbstractSynchronousByteArrayCommandTransport.read(AbstractSynchronousByteArrayCommandTransport.java:35)
at
hudson.remoting.SynchronousCommandTransport$ReaderThread.run(SynchronousCommandTransport.java:63)
ERROR: Process terminated with exit code 1 java.io.IOException:
Unexpected EOF at
hudson.remoting.ChunkedInputStream.readUntilBreak(ChunkedInputStream.java:99)
at
hudson.remoting.ChunkedCommandTransport.readBlock(ChunkedCommandTransport.java:39)
at
hudson.remoting.AbstractSynchronousByteArrayCommandTransport.read(AbstractSynchronousByteArrayCommandTransport.java:35)
at
hudson.remoting.SynchronousCommandTransport$ReaderThread.run(SynchronousCommandTransport.java:63)
Also: hudson.remoting.Channel$CallSiteStackTrace: Remote call to
rtt-ci-euhrhd0036vdeas at
hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1741)
at hudson.remoting.Request.call(Request.java:202) at
hudson.remoting.Channel.call(Channel.java:954) at
hudson.slaves.SlaveComputer.setChannel(SlaveComputer.java:549) at
hudson.slaves.SlaveComputer.setChannel(SlaveComputer.java:416) at
hudson.slaves.CommandLauncher.launch(CommandLauncher.java:153) at
hudson.slaves.SlaveComputer$1.call(SlaveComputer.java:288) at
jenkins.util.ContextResettingExecutorService$2.call(ContextResettingExecutorService.java:46)
at
jenkins.security.ImpersonatingExecutorService$2.call(ImpersonatingExecutorService.java:71)
at java.util.concurrent.FutureTask.run(Unknown Source) at
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source) Caused:
hudson.remoting.RequestAbortedException at
hudson.remoting.Request.abort(Request.java:340) at
hudson.remoting.Channel.terminate(Channel.java:1038) at
hudson.remoting.SynchronousCommandTransport$ReaderThread.run(SynchronousCommandTransport.java:96)
如果我在Manage Jenkins中禁用SSHD端口 – >配置安全性,然后我就可以启动我的奴隶了.但是在我的脚本中,我将使用Jenkins-cli.jar触发一个作业,将二进制文件从master复制到slave.
java -jar jenkins-cli.jar -s http:// localhost:8080 –ssh -user username -i~ / .ssh / id_rsa build RTT / RTT-CI-Tools / RTT-CI-Tools-Distribute -s – p SLAVE_REGEX =从属名称
我收到的消息是
"WARNING: No header 'X-SSH-Endpoint' returned by Jenkins"
并且构建不会被触发.我也尝试过在jenkins-cli.jar命令中将-ssh替换为-http,
java -jar jenkins-cli.jar -s http:// localhost:8080 -http -auth用户名:60b3450a883a2519592af84cdcd0d224 build $CI_JOB -s -p SLAVE_REGEX = $SLAVEHOST
它触发了这项工作.再次无法启动从机,
<===[JENKINS REMOTING CAPACITY]===>Exception in thread “main”
java.io.StreamCorruptedException: invalid stream header: 099FACED at
java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:808)
at java.io.ObjectInputStream.(ObjectInputStream.java:301) at
hudson.remoting.ObjectInputStreamEx.(ObjectInputStreamEx.java:48)
at
hudson.remoting.ChannelBuilder.makeTransport(ChannelBuilder.java:478)
at hudson.remoting.ChannelBuilder.negotiate(ChannelBuilder.java:433)
at hudson.remoting.ChannelBuilder.build(ChannelBuilder.java:354) at
hudson.remoting.Launcher.main(Launcher.java:743) at
hudson.remoting.Launcher.runWithStdinStdout(Launcher.java:691) at
hudson.remoting.Launcher.run(Launcher.java:373) at
hudson.remoting.Launcher.main(Launcher.java:283) usage: ssh
[-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
[-D [bind_address:]port] [-e escape_char] [-F configfile]
[-i identity_file] [-L [bind_address:]port:host:hostport]
[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
[-R [bind_address:]port:host:hostport] [-S ctl_path]
[-W host:port] [-w local_tun[:remote_tun]]
[user@]hostname [command] ERROR: Unexpected error in launching an agent. This is probably a bug in Jenkins ERROR:
Connection terminated java.io.IOException: Unexpected EOF
如何解决这个问题
我相信你的脚本中有些东西正在篡改标准输入.
您的脚本应该将整个未更改的stdin流传递给Jenkins代理进程.
通用解决方案
OP建立Jenkins会话的命令与我的不同,但无论如何,您应该将启动脚本分成3个主要部分:
设置:此部分不要篡改stdin或stdout.
建立Jenkins会话:java -jar jenkins-cli.jar …
撕下:在这部分没有篡改stdin或stdout.
#!/bin/bash
function set_up {
# your set-up code here
}
function tear_down {
# your tear-down code here
}
function main {
# set-up (no stdin,no stdout)
set_up "$@" < /dev/null > /dev/null || exit $?
# establish Jenkins session
java -jar jenkins-cli.jar -blah -blah -blah
# tear-down (no stdin,no stdout)
tear_down "$@" < /dev/null > /dev/null || exit $?
}
main "$@"
但为什么?
启动脚本的工作是在主代理和构建代理之间建立一个未被禁止的通信通道(通过stdin和stdout).
+------------+
"Hello Agent" | |
_ _ ----+ +----
v Hello Agent ->
----+ +----
| |
| | "Hello Master"
----+ +---- _ _
<- Hello Master v
----+ +----
| |
+------------+
launch
script
如果此通信渠道被篡改,Jenkins将无法正常工作.
+------------+
"Hello Agent" | |
_ _ ----+ +-----------
v Hel PLZ SEND HELP!! t ->
----+ +-----------
| |
| |
----+ +---- | |
^
----+ +----
| |
+------------+
launch
script
如果你没有将任何东西输入到该命令中,一些Unix命令可能会“吞下”你的启动脚本的stdin,从而“破坏”通信通道.请考虑以下脚本.
#!/bin/bash
function keep_stdin_intact {
printf 'I do not consume any stdin,' >&2
echo 'and I do not alter the original stdout.' >&2
}
function swallow_stdin {
echo 'I swallow stdin. Did you see any hexdump below?' >&2
read yn # read consumed some stdin
}
echo 'yes' | { keep_stdin_intact; cat -; } | xxd
echo 'yes' | { swallow_stdin; cat -; } | xxd
echo "no you can't now :P" | { swallow_stdin < /dev/null; cat -; } | xxd
>第一个是管道输出和十六进制转储,因为keep_stdin_intact没有篡改stdin,在这种情况下,是“是”流.
>第二个是,因为swallow_stdin消耗了它,所以cat没有任何东西可以捕捉,xdd没有任何东西可读.
>通过管道/ dev / null到stdin-swallowing命令,我们保护自己的stdin.
怎么了ssh?
ssh是吞噬你的stdin的邪恶命令之一.
假设您要在运行agent.jar之前删除构建代理上的某些文件.没有样板,你可能会写:
ssh $OPTIONS "$remote" 'sudo rm -rf /var/log/Nginx/*'
ssh $OPTIONS "$remote" 'cd $HOME && java -jar agent.jar'
^但这是错的!第一个ssh命令将吞下你的stdin,Jenkins会话将没有任何东西可读.
第一个ssh必须“沉默”.传递/ dev / null作为其stdin.
ssh $OPTIONS "$remote" 'sudo rm -rf /var/log/Nginx/*' < /dev/null
ssh $OPTIONS "$remote" 'cd $HOME && java -jar agent.jar'