Jenkins - 通过 SSH 发布 - EXEC:STDOUT/STDERR - bash:服务:找不到命令

Abo*_*oed 5 ssh bash exec jenkins

我对 Publish Over SSH 插件有问题,并且已经尝试了很多可能的解决方案,但仍然不起作用:

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

执行脚本

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
Run Code Online (Sandbox Code Playgroud)

控制台输出

    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
Run Code Online (Sandbox Code Playgroud)

我的 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
Run Code Online (Sandbox Code Playgroud)

远程服务器.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
Run Code Online (Sandbox Code Playgroud)

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

abe*_*abe 3

尝试输入“service”的完整路径,即..将“service”替换为“/usr/sbin/service”

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