Where is the implementation of the slave execute shell command source code

44 views
Skip to first unread message

李立泓

unread,
Jun 10, 2016, 1:11:28 AM6/10/16
to Jenkins Developers




when slave execute shell,I found that it maybe a non interactive non login shell

I check some information,it does the equivalent of running  "ssh slavehost command..."

I check <a href="https://github.com/jenkinsci/remoting">https://github.com/jenkinsci/remoting</a>,as slave.jar,but I no find how slave execute shell command

Where is the implementation of the slave execute shell command source code? 

Robert Sandell

unread,
Jun 10, 2016, 4:58:09 AM6/10/16
to jenkin...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/df607837-2891-416a-922a-9f5e43934722%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Robert Sandell
Software Engineer
CloudBees Inc.

Oliver Gondža

unread,
Jun 10, 2016, 5:36:52 AM6/10/16
to jenkin...@googlegroups.com
Just to add, if it will be executed in the context of login/interactive
shell is based on the way you launch the agent (environment variables
will be inherited from shell to agent and from agent to your process)
and the way you define the bash shell script (it interprets shebang at
the beginning of the script IIRC, so can choose the interpreter and
provide options for it).

--
oliver

李立泓

unread,
Jun 10, 2016, 5:51:07 AM6/10/16
to Jenkins Developers
Thank you for your answer.I debug begin CommandInterpreter.perform ,found that shell.buildCommandLine return [/bin/sh, -xe, /tmp/hudson3908940237320515344.sh]  

Now I have two questions.

1.slave execute shell ,  does  it the equivalent of running  "ssh slavehost command..." ?
2.Slave Executing the Remote Request. Which method is the specific  implementation of the slave side,I  didn't find like  "ssh slavehost command..." implementation method on the remoting(slave.jar)  project

在 2016年6月10日星期五 UTC+8下午4:58:09,Robert Sandell写道:

Robert Sandell

unread,
Jun 10, 2016, 6:04:00 AM6/10/16
to jenkin...@googlegroups.com
1. No, the channel protocol can use ssh but doesn't have to, the transport layer is further down in the stack. The actual execution of the command is performed on the agent/slave bu the slave.jar process and the request to do so is a command sent over the remoting channel from the master, what you see on line 95 [1] is a helper method to sent that command to the slave.jar process on the agent.

[1] https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/hudson/tasks/CommandInterpreter.java#L95


For more options, visit https://groups.google.com/d/optout.

李立泓

unread,
Jun 10, 2016, 6:29:07 AM6/10/16
to Jenkins Developers
Thank you for your answer.Your suggestion is very good. 
-i        If the -i option is present, the shell is interactive.
-l        Make bash act as if it had been invoked as a login shell (see INVOCATION below).

-i -l  can make bash  login/interactive shell 

but  I would like to know  Which method is the specific  implementation of the slave side

but cannot debug  remote slave.jar(remoting project),code logic is a bit difficult to understand

so, I hope you can help me to answer this question:
Slave Executing the Remote Request. Which method is the specific  implementation of the slave side,I  didn't find implementation method on the remoting(slave.jar)  project

在 2016年6月10日星期五 UTC+8下午5:36:52,ogondza写道:

Oliver Gondža

unread,
Jun 10, 2016, 7:32:31 AM6/10/16
to jenkin...@googlegroups.com
On 06/10/2016 12:29 PM, 李立泓 wrote:

> but I would like to know Which method is the specific implementation
> of the slave side

The slave.jar has no idea it will execute the shell build step one day.
In fact it does not, the build step (from implementation perspective) is
executed on master and it just happen to be running a process on slave
using hudson.Launcher. The slave.jar does not know anything about that
class either as it just simply listens to masters commands (java classes
sent over channel accompanied with class definitions) and execute that.

HTH
--
oliver
Reply all
Reply to author
Forward
0 new messages