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

标签 bash jenkins ssh exec

我对 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

控制台输出

    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

我是否遗漏了任何配置或步骤?

最佳答案

尝试放置“服务”的完整路径,即.. 将“服务”替换为“/usr/sbin/service”

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

关于bash - Jenkins - 通过 SSH 发布 - EXEC : STDOUT/STDERR - bash: service: command not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41237095/

相关文章:

linux - 如何在自定义 bash 函数中传递参数作为目录路径的一部分?

linux - 比 tee 更好的输出到控制台和输出文件的方法?

c - 没有 df -i 的 inode 使用

amazon-ec2 - 在 Amazon Linux 上安装和管理 Jenkins

java - 当使用 JSch 通过 Java 执行时,某些 Unix 命令会失败并返回 "... not found"

Bash 解析 docker status 检查本地镜像是否是最新的

java - Jenkins无法识别gradle子项目的测试

node.js - 从 NodeJS 进程获取 Jenkins BUILD 详细信息

git - 使用 ssh 连接到实时服务器并将我的 git 推送到其中

linux - Linux 中的用户特定主机