Extracting shell script from parameterised Hudson job
- by Jonik
I have a parameterised Hudson job, used for some AWS deployment stuff, which in one build step runs certain shell commands.
However, that script has become sufficiently complicated that I want to "extract" it from Hudson to a separate script file, so that it can easily be versioned properly. The Hudson job would then simply update from VCS and execute the external script file.
My main question is about passing parameters to the script. I have a Hudson parameter named AMI_ID and a few others. The script references those params as if they were environment variables:
echo "Using AMI $AMI_ID and type $TYPE"
Now, this works fine inside Hudson, but not if Hudson calls an external script. Could I somehow make Hudson set the params as environment variables so that I don't need to change the script? Or is my best option to alter the script to take command line parameters (and possibly assign those to named variables for readability: ami_id=$1; type=$2; ... )?
I tried something like this but the script doesn't get correctly replaced values:
export AMI_ID=$AMI_ID
export TYPE=$TYPE
external-script.sh # this tries to use e.g. $AMI_ID
Bonus question: when the script is inside Hudson, the "console output" will contain both the executed commands and their output. This is extremely useful for debugging when something goes wrong with a build! For example, here the line starting with "+" is part of the script and the following line its output:
+ ec2-associate-address -K pk.pem -C cert.pem 77.125.116.139 -i i-aa3487fd
ADDRESS 77.125.116.139 i-aa3487fd
When calling an external script, Hudson output will only contain the latter line, making debugging harder. I could cat the script file to stdout before running it, but that's not optimal either. In effect, I'd like a kind of DOS-style "echo on" for the script which I'm calling from Hudson - anyone know a trick to achieve this?