Jenkins - 通过SSH发布 - EXEC:STDOUT / STDERR - bash:service:command not found

时间:2016-12-20 07:40:10

标签: bash jenkins ssh exec

我遇到了Publish Over SSH插件的问题,并且已经尝试了很多可能的解决方案,但仍然无效:

  1. 在pty中使用exec
  2. 使用bash --login
  3. 使用shebang(#!/ usr / bin / env bash)
  4. 执行脚本

    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
    

    控制台输出

        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
    

    我的Jenkins使用bash作为默认shell,而远程服务器也使用bash。

    远程服务器.bashrc

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

    远程服务器.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
    

    我缺少任何配置或步骤吗?

1 个答案:

答案 0 :(得分:2)

尝试为" service"设置完整路径,即..替换" service"与" / usr / sbin / service"

添加如下所示的第一行也可能有助于设置路径 . /etc/profile