expect utility is not working when executing from jenkins

走远了吗. 提交于 2019-12-05 04:16:56

Since Jenkins doesn't run it from an actual terminal, interact doesn't work, since there can't actually be any user interaction there.

You can replace interact with

expect eof
wait

Please use var='xxxxx' instead of var="xxxxx". Hope this help.

It seems that Jenkins doesn't support the interactive command model.

Try to use sshpass tool to pass the password in a non-interactive way.

install sshpass

$ sshpass -p "password" {your command}
ruhsuzbaykus

This question is very similar to: Jenkins not waiting on call to a bash script with expect; for those encountering the similar problem, especially when using "su" utility to change the user, please be aware that Jenkins closes the SSH connection as soon as the user is changed. You can not continue giving commands with the new user. Design your script in such a way that you are sending the command directly, such as:

spawn su - username -c "yoursinglewordcommand"

and then the rest of the expect script as usual (I was also successful with the interact command).

You may use ssh steps plugin. This plugin will provide steps like sshScript which executes given script(file) on remote node and responds with output, sshCommand that executes given command on remote node and responds with output and also sshPut, sshGet, sshRemove.

Add to your Jenkinsfile :

node {
   def remote = [:]
   remote.name = 'test'
   remote.host = 'test.domain.com'
   remote.user = 'root'
   remote.password = 'password'
   remote.allowAnyHosts = true
   stage('Remote SSH') {
      sshCommand remote: remote, command: "cp /abcd/sjws/config/obj.conf /abcd/sjws/config/obj.conf_jenkins"
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!