Build failing to execute "spawn/expect" shell command

1,104 views
Skip to first unread message

Ranjith P

unread,
Oct 10, 2013, 8:51:58 AM10/10/13
to jenkins...@googlegroups.com
HI,

I have written a shell command to copy the build artifacts to a server in Post build action. 

Script:
---------

#!/usr/bin/expect -f
#!usr/bin/expect
set pass "password"
spawn scp -r ${WORKSPACE}/my_project/target/*.jar  us...@192.168.1.1:/usr/local/jars
expect "*Password:*"
send "${pass}\r";
expect eof

Its not working as expected and showing exception as

/usr/local/itag/apache-tomcat-7.0.14/temp/hudson5412037345746046257.sh: line 4: spawn: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE

If I run the same script through a terminal, it will work. 

Please help me to resolve this.

Regard,
Ranjith

Stephen Connolly

unread,
Oct 10, 2013, 10:12:17 AM10/10/13
to jenkins...@googlegroups.com
wouldn't the best thing be to use a ssh key and then use the ssh-agent build wrapper to provide the key to the build... then there would be no need for any expect stuff at all?


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Les Mikesell

unread,
Oct 10, 2013, 2:00:32 PM10/10/13
to jenkinsci-users
On Thu, Oct 10, 2013 at 7:51 AM, Ranjith P <ranjit...@gmail.com> wrote:
> I have written a shell command to copy the build artifacts to a server in

That's an expect script, not a shell script...

> Post build action.
>
> Script:
> ---------
>
> #!/usr/bin/expect -f
> #!usr/bin/expect
> set pass "password"
> spawn scp -r ${WORKSPACE}/my_project/target/*.jar
> us...@192.168.1.1:/usr/local/jars
> expect "*Password:*"
> send "${pass}\r";
> expect eof
>
> Its not working as expected and showing exception as
>
> /usr/local/itag/apache-tomcat-7.0.14/temp/hudson5412037345746046257.sh: line
> 4: spawn: command not found

That means the shell is executing it, not expect. However Jenkins
starts shell scripts must be explicitly running /bin/sh or bash,
probably with some extra command line options instead of parsing the
#!interpreter line.

> If I run the same script through a terminal, it will work.

But probably not if you type:
sh scriptname

> Please help me to resolve this.

The simple way is to have an actual shell script that executes your
expect script. But using ssh keys instead of a password would avoid
the issue and also avoid have the password in a plain text file.

--
Les Mikesell
lesmi...@gmail.com
Reply all
Reply to author
Forward
0 new messages