I am using jenkins to run my builds.
One of my steps is to copy over certain files and place them inside /etc/init using sudo
<exec command="ssh -A ${host-used} '/etc/init.d/ConvertDaemon stop'" outputProperty="result" escape="false">
</exec>
<echo msg="${result}" />
<exec command="ssh -A ${host-used} 'sudo Console/cake init_runners copy_runners_into_initd'" outputProperty="result" escape="false" />
<echo msg="${result}" />
${host-used} returns www-data@ip-address
The issue is the 2nd command.
When I run the 1st command, i can see my result printed out in the console log in jenkins.
For the 2nd command, I get a no tty present
message
So I changed the 2nd command to
<exec command="ssh -t ${host-used} -A ${host-used} 'sudo Console/cake init_runners copy_runners_into_initd'" outputProperty="result" escape="false" />
<echo msg="${result}" />
I get a
Pseudo-terminal will not be allocated because stdin is not a terminal
How do I overcome this?
UPDATE:
I tried this as well.
<exec command="ssh -t -t ${host-used} -A ${host-used} 'sudo Console/cake init_runners copy_runners_into_initd'" outputProperty="result" escape="false" />
<echo msg="${result}" />
I got:
bash: www-data@ipaddress: command not found
Connection to ipaddress closed.
I want to emphasize that the command is correctly used. BUT I cannot read the message.
UPDATE2:
There are times when you ask a question, but then you realize the question you want to ask is not the REAL question you want to solve.
This question is like that.
All I wanted to do is to execute a few commands run by jenkins and see the print out of the commands. These commands happen to require sudo.
Jenkins basically ssh as another user www-data to perform these commands.
I was having trouble with printing out the results in jenkins for those commands requiring sudo.
Having spent a lovely saturday working on this with some very helpful SO answers, I realized that I could simply try to execute those commands without sudo by having jenkins ssh as root instead.
It worked.
I am going to answer this question with that approach instead because that is all I wanted -- execute some commands inside jenkins and see their print out.