Aboed
Aboed

Reputation: 51

Jenkins - Publish Over SSH - EXEC: STDOUT/STDERR - bash: service: command not found

I have issue with Publish Over SSH plugin and already try so many possible solution, but still doesn't work:

  1. using exec in pty
  2. using bash --login
  3. using shebang (#!/usr/bin/env bash)

Exec Script

service monitoring-daemon stop
cd /home/push/monitoring/target
rm -rf Monitoring.jar
ls -la | grep Monitoring | grep -v grep | awk '{print $9}' | xargs -I file mv file Monitoring.jar
service monitoring-daemon start

Console Output

    10:26:25 SSH: EXEC: STDOUT/STDERR from command [service monitoring-daemon stop
    10:26:25 cd /home/push/monitoring/target
    10:26:25 rm -rf Monitoring.jar
    10:26:25 ls -la | grep Monitoring | grep -v grep | awk '{print $9}' | xargs -I file mv file Monitoring.jar
    10:26:25 service monitoring-daemon start] ...
    10:26:25 SSH: EXEC: connected
    10:26:25 bash: service: command not found
    10:26:25 bash: line 4: service: command not found
    10:26:25 SSH: EXEC: completed after 201 ms
    10:26:25 SSH: Disconnecting configuration [*********] ...
    10:26:25 ERROR: Exception when publishing, exception message [Exec exit status not zero. Status [127]]
    10:26:25 Build step 'Send files or execute commands over SSH' changed build result to UNSTABLE
    10:26:25 [ANALYSIS-COLLECTOR] Computing warning deltas based on reference build #48

My Jenkins is using bash as default shell, and remote server also bash.

Remote Server .bashrc

# .bashrc
alias service='/sbin/service'
# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# User specific aliases and functions

Remote Server .bash_profile

# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin
export PATH

is there any piece of configuration or step that I'm missing?

Upvotes: 5

Views: 7050

Answers (1)

abe
abe

Reputation: 341

Try putting the full path for "service", ie.. replace "service" with "/usr/sbin/service"

Adding a first line like below might also help set your path . /etc/profile

Upvotes: 3

Related Questions