0

I'm running the latest version of Jenkins on CentOS. In my Jenkins job, I can run post build steps, and included this command,

sudo /bin/rm /usr/java/jboss/server/default/deploy/myclient-1.0.war

which dies with the error

sudo: sorry, you must have a tty to run sudo

Is there a way I can rewrite the above to run the command through a tty shell? In our /etc/sudoers file, we have the line

Defaults    requiretty

but our sysadmin has forbade us from commenting it out.

1
  • 4
    Is there some reason you have to deploy as root? It sounds like you and the sysadmin need to have a long talk. Sep 17, 2012 at 16:56

3 Answers 3

1

If /usr/java/jboss/server/default/deploy/myclient-1.0.war has to be removed by root you might be doing something wrong. I can't think of a good reason that file would need to be owned by root.

The other option is to see how your sysadmin feels about disabling requiretty for that one command.

Cmnd_Alias           NOTTYCMD = /bin/rm /usr/java/jboss/server/default/deploy/myclient-1.0.war
Defaults!NOTTYCMD   !requiretty
2
  • Could you explain your comment " ... has to be removed by root you might be doing something wrong "? The files in the deploy directory are owned by the 'jboss' user with 755 perms and Jenkins runs under user 'jenkins'.
    – Dave
    Sep 17, 2012 at 19:19
  • @Dave Since the file is owned by jboss then it can be removed by jboss. No need to involve root.
    – ablackhat
    Feb 3, 2014 at 8:04
1

but our sysadmin has forbade us from commenting it out.

He can disable only for the jenkins user:

Defaults:jenkins    !requiretty

The files in the deploy directory are owned by the jboss user with 755 perms and Jenkins runs under user jenkins.

or make the deploy folder group writable and set the SGID bit:

chmod -R g+w /usr/java/jboss/server/default/deploy/
chmod g+s /usr/java/jboss/server/default/deploy/

and add the jenkins user to the jboss group:

usermod -a -G jboss jenkins

then you can delete /usr/java/jboss/server/default/deploy/myclient-1.0.war without using sudo.

1

I had this problem too when trying to start jboss as jboss user. The problem was solved by changing a line in the file /etc/init.d/jboss in the following way:

before: su - $JBOSS_USER -c "LAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT -c $JBOSS_CONFIG" 2>&1 > $JBOSS_CONSOLE_LOG &

after: su - $JBOSS_USER -c "LAUNCH_JBOSS_IN_BACKGROUND=1 JBOSS_PIDFILE=$JBOSS_PIDFILE $JBOSS_SCRIPT -c $JBOSS_CONFIG 2>&1 > $JBOSS_CONSOLE_LOG &"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .