我正在尝试在Jenkins文件中切换用户,然后运行命令。在Linux机器上运行此命令可以正常工作,但是在Jenkins中运行它时会出现以下错误:
su: unrecognized option '--stop'
Try `su --help' for more information.
我希望执行的命令:
su - testuser -c 'testcontrol --stop --app testfeed --no_prompt_on_change'
My Jenkinsfile:
node {
echo 'Stopping Feed'
CHEF_SERVER = sh (script: 'grep chef_server_url /etc/chef/client.rb | awk -F\'/\' \'{print $3}\'', returnStdout: true).trim()
TARGET_SERVER = "foo"
stage('Switching userstopping process') {
try {
echo sh(script: "ssh ${CHEF_SERVER} salt ${TARGET_SERVER} cmd.run \\'su - testuser -c 'testcontrol --stop --app testfeed --no_prompt_on_change'\\'", returnStdout: true)
}
catch (e) {
// catch error code here
}
}
}