title: how to use sudo command in jenkins exec command
body: <p>I am using jenkins to run my builds.</p>
  
  <p>One of my steps is to copy over certain files and place them inside /etc/init using sudo</p>
  
  <pre><code>    &lt;exec command="ssh -A ${host-used} '/etc/init.d/ConvertDaemon stop'" outputProperty="result" escape="false"&gt;
      &lt;/exec&gt;
      &lt;echo msg="${result}" /&gt;
  
      &lt;exec command="ssh -A ${host-used} 'sudo Console/cake init_runners copy_runners_into_initd'" outputProperty="result" escape="false" /&gt;
      &lt;echo msg="${result}" /&gt;
  
  ${host-used} returns www-data@ip-address
  </code></pre>
  
  <p>The issue is the 2nd command.</p>
  
  <p>When I run the 1st command, i can see my result printed out in the console log in jenkins.</p>
  
  <p>For the 2nd command, I get a <code>no tty present</code> message</p>
  
  <p>So I changed the 2nd command to </p>
  
  <pre><code>    &lt;exec command="ssh -t ${host-used} -A ${host-used} 'sudo Console/cake init_runners copy_runners_into_initd'" outputProperty="result" escape="false" /&gt;
      &lt;echo msg="${result}" /&gt;
  </code></pre>
  
  <p>I get a</p>
  
  <pre><code> Pseudo-terminal will not be allocated because stdin is not a terminal
  </code></pre>
  
  <p>How do I overcome this?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I tried this as well. </p>
  
  <pre><code>    &lt;exec command="ssh -t -t ${host-used} -A ${host-used} 'sudo Console/cake init_runners copy_runners_into_initd'" outputProperty="result" escape="false" /&gt;
      &lt;echo msg="${result}" /&gt;
  </code></pre>
  
  <p>I got:</p>
  
  <pre><code>bash: www-data@ipaddress: command not found
  Connection to ipaddress closed.
  </code></pre>
  
  <p><strong>I want to emphasize that the command is correctly used. BUT I cannot read the message.</strong></p>
  
  <hr>
  
  <p><strong>UPDATE2:</strong></p>
  
  <p>There are times when you ask a question, but then you realize the question you want to ask is not the <em>REAL</em> question you want to solve.</p>
  
  <p>This question is like that.</p>
  
  <p>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.</p>
  
  <p>Jenkins basically ssh as another user www-data to perform these commands.</p>
  
  <p>I was having trouble with printing out the results in jenkins for those commands requiring sudo.</p>
  
  <p>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 <em>without sudo by having jenkins ssh as root instead.</em></p>
  
  <p>It worked. </p>
  
  <p>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.</p>