title: How to use sudo in build script for gitlab ci?
body: <p>When I would like to do something that requiers sudo privelegies, the build process stucks and when <code>ps aux</code> for that command, it hanging in the list but doing nothing.</p>
  
  <p>E.g.:</p>
  
  <p>in the buildscript:</p>
  
  <pre><code># stop nginx
  echo "INFO: stopping nginx. pid [$(cat /opt/nginx/logs/nginx.pid)]"
  sudo kill $(cat /opt/nginx/logs/nginx.pid)
  </code></pre>
  
  <p>in the gitlab ci output console:</p>
  
  <pre><code>INFO: stopping nginx. pid [2741]
  
  kill $(cat /opt/nginx/logs/nginx.pid) # with a spinning wheel
  </code></pre>
  
  <p>in the bash:</p>
  
  <pre><code>&gt; ps aux | grep nginx
  
  root      6698  0.0  0.1  37628  1264 ?        Ss   19:25   0:00 nginx: master process /opt/nginx/sbin/nginx
  nobody    6700  0.3  0.3  41776  3832 ?        S    19:25   0:00 nginx: worker process
  kai   7015  0.0  0.0   4176   580 pts/0    S+   19:27   0:00 sh -c sudo kill $(cat /opt/nginx/logs/nginx.pid)
  kai   7039  0.0  0.0   7828   844 pts/2    S+   19:27   0:00 grep nginx
  </code></pre>
  
  <p>So:</p>
  
  <ul>
  <li>not the <code>sudo kill $(cat /opt/nginx/logs/nginx.pid)</code> is going to execute, but <code>sh -c sudo kill $(cat /opt/nginx/logs/nginx.pid)</code></li>
  <li>it is hanging up, without response (sounds for me like it asks for a password interactively)</li>
  </ul>