Hudson GUI 无法使用从 shell 中正常运行的相同命令来运行作业

Hudson GUI 无法使用从 shell 中正常运行的相同命令来运行作业

我在 hudson 中尝试运行作业时收到此错误,以下是日志

Started by user anonymous
[workspace] $ /bin/bash -x /tmp/hudson3189813701500418318.sh
+ date
Thu Feb 19 17:02:03 EST 2015
+ fab -f /FABRIC/FABFILESv1/deploy_ansiblev1.py -H 192.168.23.151 deploy_ansible
/usr/lib64/python2.6/getpass.py:83: GetPassWarning: Can not control echo on the terminal.
  passwd = fallback_getpass(prompt, stream)
Warning: Password input may be echoed.
[192.168.23.151] Login password for 'root': [192.168.23.151] Executing task 'deploy_ansible'
[192.168.23.151] run: cd /ANSIBLE/ANSIBLEv1/PLAYBOOKSv1
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/fabric/main.py", line 743, in main
    *args, **kwargs
  File "/usr/lib/python2.6/site-packages/fabric/tasks.py", line 384, in execute
    multiprocessing
  File "/usr/lib/python2.6/site-packages/fabric/tasks.py", line 274, in _execute
    return task.run(*args, **kwargs)
  File "/usr/lib/python2.6/site-packages/fabric/tasks.py", line 174, in run
    return self.wrapped(*args, **kwargs)
  File "/FABRIC/FABFILESv1/deploy_ansiblev1.py", line 7, in deploy_ansible
    run('cd /ANSIBLE/ANSIBLEv1/PLAYBOOKSv1')
  File "/usr/lib/python2.6/site-packages/fabric/network.py", line 647, in host_prompting_wrapper
    return func(*args, **kwargs)
  File "/usr/lib/python2.6/site-packages/fabric/operations.py", line 1054, in run
    shell_escape=shell_escape)
  File "/usr/lib/python2.6/site-packages/fabric/operations.py", line 921, in _run_command
    channel=default_channel(), command=wrapped_command, pty=pty,
  File "/usr/lib/python2.6/site-packages/fabric/state.py", line 397, in default_channel
    chan = _open_session()
  File "/usr/lib/python2.6/site-packages/fabric/state.py", line 389, in _open_session
    return connections[env.host_string].get_transport().open_session()
  File "/usr/lib/python2.6/site-packages/fabric/network.py", line 159, in __getitem__
    self.connect(key)
  File "/usr/lib/python2.6/site-packages/fabric/network.py", line 151, in connect
    user, host, port, cache=self, seek_gateway=seek_gateway)
  File "/usr/lib/python2.6/site-packages/fabric/network.py", line 531, in connect
    password = prompt_for_password(text)
  File "/usr/lib/python2.6/site-packages/fabric/network.py", line 612, in prompt_for_password
    new_password = _password_prompt(password_prompt, stream)
  File "/usr/lib/python2.6/site-packages/fabric/network.py", line 584, in _password_prompt
    return getpass.getpass(prompt.encode('ascii', 'ignore'), stream)
  File "/usr/lib64/python2.6/getpass.py", line 83, in unix_getpass
    passwd = fallback_getpass(prompt, stream)
  File "/usr/lib64/python2.6/getpass.py", line 118, in fallback_getpass
    return _raw_input(prompt, stream)
  File "/usr/lib64/python2.6/getpass.py", line 135, in _raw_input
    raise EOFError
EOFError
Finished: FAILURE

现在相同的命令可以通过 CLI 顺利运行

[root@bbhudson ~]# fab -f /FABRIC/FABFILESv1/deploy_ansiblev1.py -H 192.168.23.151 deploy_ansible
[192.168.23.151] Executing task 'deploy_ansible'
[192.168.23.151] run: cd /ANSIBLE/ANSIBLEv1/PLAYBOOKSv1
[192.168.23.151] run: ansible-playbook -i /ANSIBLE/ANSIBLEv1/PLAYBOOKSv1/hosts /ANSIBLE/ANSIBLEv1/PLAYBOOKSv1/stg-servers.yml
[192.168.23.151] out:  [WARNING]: The version of gmp you have installed has a known issue regarding
[192.168.23.151] out: timing vulnerabilities when used with pycrypto. If possible, you should update
[192.168.23.151] out: it (i.e. yum update gmp).
[192.168.23.151] out:
[192.168.23.151] out:
[192.168.23.151] out: PLAY [stg-servers] ************************************************************
[192.168.23.151] out:
[192.168.23.151] out: GATHERING FACTS ***************************************************************
[192.168.23.151] out: ok: [192.168.23.77]
[192.168.23.151] out:
...
...

这是什么原因造成的?我已经重启了服务器,但没用。

谢谢

添加:

刚刚意识到 Hudson 作业以 Hudson 用户身份运行,那么我该怎么做才能解决这个问题?作业需要 root 用户才能运行...作业运行时需要 SSH 身份验证

见下文

[root@bbhudson ~]# ps aux | grep hudson
root      1134  0.0  0.1 108436  1160 ?        S    Feb19   0:00 /bin/sh /etc/rc3.d/S50hudson start
root      1136  0.0  0.1 131176  1420 ?        S    Feb19   0:00 runuser -s /bin/bash hudson -c ulimit -S -c 0 >/dev/null 2>&1 ; /usr/bin/java -Djava.awt.headless=true -DHUDSON_HOME=/var/lib/hudson -jar /usr/lib/hudson/hudson.war --logfile=/var/log/hudson/hudson.log --daemon --httpPort=8080 --debug=5 --handlerCountMax=100 --handlerCountMaxIdle=20
hudson    1149  0.0  0.1 106060  1324 ?        Ss   Feb19   0:00 bash -c ulimit -S -c 0 >/dev/null 2>&1 ; /usr/bin/java -Djava.awt.headless=true -DHUDSON_HOME=/var/lib/hudson -jar /usr/lib/hudson/hudson.war --logfile=/var/log/hudson/hudson.log --daemon --httpPort=8080 --debug=5 --handlerCountMax=100 --handlerCountMaxIdle=20
hudson    1150  0.1 16.6 1117940 169604 ?      Sl   Feb19   1:20 /usr/bin/java -Djava.awt.headless=true -DHUDSON_HOME=/var/lib/hudson -jar /usr/lib/hudson/hudson.war --logfile=/var/log/hudson/hudson.log --daemon --httpPort=8080 --debug=5 --handlerCountMax=100 --handlerCountMaxIdle=20
root     11133  0.0  0.0 103244   868 pts/0    S+   11:33   0:00 grep hudson

答案1

刚刚发现,运行 Hudson 的用户没有运行该作业所需的权限

我实际上在指定的用户下重新安装了 jenkins(这次不是 hudson,无论如何都要迁移),并使用具有正确权限的用户创建了完全相同的作业来运行该作业,然后 BANG !!!

有效!!!

谢谢

答案2

使用此功能代替运行命令和炸弹。

output['running']  = False     # Avoid fabric to output what it is doing behind the scenes
output['stdout']   = False     # Do not show stdout
output['stderr']   = False     # Do not show stderr
output['status']   = False     # Prevent fabric from using print in some situations (at least in disconnect_all)
output['warnings'] = False     # Avoid fabric from showing messages about failed commands

def run_it(command, user, host, port, keyfile):
    env.host_string = "%s@%s:%s" % (user, host, port)
    env.key_filename = keyfile
    try:
        res = run(command, pty=False, shell=True)
        print "SUCCESS: return_code=%s" % (return_code)
    except Exception, e:
        print "ERROR  : %s" % (e)
        stdout, return_code =  None, None
    return stdout, return_code

PS 不要将密钥列表传递给 env.key_filename

相关内容