0

This is also a bash question. I have a script that when run ./recompile it asks 3 questions, separately, 1 at a time.

The answers are as follows: 1, 1, y.

So I need jenkins to run my script, but to also answer the questions.

Jenkins has this execute shell box, which I take is basically a bash script entry point.

So I have set it to execute my script, but I don't know how to simulate the answers.

I did something like this

./recompile
1
1
y

and

./recompile && 1 && 1 && y

But it says 1 is not a command....

What bash command am I looking for to pass the parameters that will be asked after the script is ran?

EDIT

When the script is run, it should start off like this.

    $ ./recompile

Choose the environment to recompile:  1) Dev  2) Stage  3) Prod ? 1
Use Watch mode?y
Will WATCH after dump completed. Use ctrl+c to exit

You are about to recompile Symfony DEV Environment, please verify the following settings:
------------------------------------------
- DEV
- clear cache
- install assets as symlinks
- watch assets, includes force dumping (use ctrl+c to exit)
Ready to run? y

---------------------------
running 
AncientSwordRage
  • 7,086
  • 19
  • 90
  • 173
blamb
  • 4,220
  • 4
  • 32
  • 50
  • 3
    Can you write the script not to need arguments (possibly only when run from jenkins)? If not and the script reads from standard input you might be able to use something like `printf '1\n1\ny\n | ./recompile`. – Etan Reisner Apr 16 '15 at 00:15
  • yes i can, i have done that until this is resolved. thanks, i will try that, that looks like its worth a try, but the questions come after the script, so why did you write it like that? does it printf after it has ./recompiled there? results in `[workspace] $ /bin/sh -xe /tmp/hudson6420186161127898135.sh /tmp/hudson6420186161127898135.sh: line 2: unexpected EOF while looking for matching `'' Build step 'Execute shell' marked build as failure Finished: FAILURE` – blamb Apr 16 '15 at 00:16
  • well i almost have it working like that. `recompile && printf '1\n1\ny\n'` yields `./recompile && printf 'You are about to recompile Symfony Environment, please verify the following settings: ------------------------------------------ - + printf '1\n1\ny\n' 1 1 y Finished: SUCCESS'` Notice the part where it asks you to please verify teh settings, thats when i need the 1,y,y printed out. it looks like i need one mnore pause or someting? the printf does spit out the text, although it does say success, yu can clearly see the script didnt run. if it did you will see what i just put in OP. – blamb Apr 16 '15 at 00:23
  • The questions do not come **after** the script. They come **from** the script. You need to pipe the output from `printf` to the script on standard input so that the script can read them from there when it tries to get the answers. `printf '....' | ./recompile`. – Etan Reisner Apr 16 '15 at 01:45
  • 1
    But rewriting the script to detect jenkins (and other non-interactive situations) and use sane defaults is a generally better idea than this I think. Or adding support for a config file that can be used in the jenkins case. – Etan Reisner Apr 16 '15 at 01:45
  • i agree with your idea to rewrite the script to work with jenkins. i am the author of that script what i have for now is i have just the same commands that run ont he script, ran from jenkins for now, until this is resolved.. – blamb Apr 16 '15 at 04:05

1 Answers1

1

You need to redirect STDIN into your script

$ echo "a
> b
> c" | sh a.sh
a
b
c
a  b  c

with this sort of bash script for a.sh

#!/bin/bash

echo "a"
read $a

echo "b"
read $b

echo "c"
read  $c

echo "a ${a} b ${b} c ${c}"
Community
  • 1
  • 1
KeepCalmAndCarryOn
  • 8,817
  • 2
  • 32
  • 47
  • this sounds more like the techo-jargon i was looking for. get right back with ya. thanks! – blamb Apr 16 '15 at 00:29
  • that certainly got it closer.. `[workspace] $ /bin/sh -xe /tmp/hudson801704658219895921.sh + echo '1 >1 >y' + /recompile /recompile: line 1: ii#!/bin/bash: No such file or directory You are about to recompile Symfony DEV Environment, please verify the following settings: ------------------------------------------ - DEV Finished: SUCCESS` ill keep tweaking with it. i think the last "y" is coming too quickly, maybe a pause will help.. – blamb Apr 16 '15 at 00:34