jenkins job起停远程slave机器上的系统服务

目标:jenkins job起停远程slave机器上的系统服务

问题1: 将jenkins用户加到root和wheel用户组后,执行系统命令时提示输入密码
[jenkins@hostname ~]$ groups
jenkins root wheel docker
[jenkins@hostname ~]$ systemctl start postfix
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to manage system services or units.
Authenticating as: jenkins
Password:
[jenkins@hostname ~]$ sudo systemctl start postfix
[sudo] password for jenkins:

解决办法:
vi /etc/sudoers

## Allows people in group wheel to run all commands
#%wheel ALL=(ALL)       ALL

## Same thing without a password
%wheel  ALL=(ALL)       NOPASSWD: ALL

问题2: jenkins job远程起停服务时报错如下
[start_smtp] $ /bin/sh -xe /tmp/jenkins2922363617810746173.sh
+ sudo systemctl start postfix
sudo: sorry, you must have a tty to run sudo

解决办法:
vi /etc/sudoers
# Defaults    requiretty

原文地址:https://www.cnblogs.com/qdlk/p/7908886.html