-
Hi, I'm looking for some samples, ideas, guidance on how to make a Bash script work with Semaphore, but the documentation seems a bit sparse. I looked around in discussions, issues and docs, but I've yet to find anything detailed enough to get things working. I've just tried a bunch of things, as described below. Normally I would do most everything using Ansible, but for one particular task there are no Ansible modules to use, so I implemented it as a bash script. My script takes some input args, like Then, my alternative test was to not use Survey Variables, but instead simply use the CLI args when running the task. This does get me a bit further, as the script actually does map those args in properly. However, for some reason that I don't understand, the script runs as Still, this is not optimal, as the end user who would use this Task would not necessarily know or understand the order of the CLI args. Therefore, using Survey Variables would be a lot better, as that would prompt the user for the right information. Well, other than the fact that, as described above, they don't map the way I expected them too. Perhaps the Task Template setup for Bash scripts should look and work differently than for how it works with Ansible? In the end, I'm considering plumbing this into an Ansible playbook from which I simply do all this using the If anyone has any pointers to what I could be doing here to get the Bash script template working, I'd greatly appreciate it. Maybe I'm completely misunderstanding how this is supposed to work? But, I have yet to find any documentation and/or samples of how it should be used. Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @mlanner thank you for your detailed description of the problem. Are you use docker image? I don't know how is it possible that bash script executed as By the arguments. Passing named variables as unnamed argument is not reliable. for a in "$@"; do
if [[ "$a" =~ ^([a-zA-Z_][a-zA-Z0-9_]*)=(.*)$ ]]; then
key="${BASH_REMATCH[1]}"
val="${BASH_REMATCH[2]}"
declare "$key=$val"
fi
done
echo $MY_ARG1
echo $MY_ARG2 ./script.sh MY_ARG1=2 MY_ARG2=hello I will add this to docs asap. |
Beta Was this translation helpful? Give feedback.
Hi @mlanner thank you for your detailed description of the problem.
Are you use docker image? I don't know how is it possible that bash script executed as
root
when your Semaphore run assemaphore
without sudo.By the arguments. Passing named variables as unnamed argument is not reliable.
You can use simple code to convert args to vars inside your script:
I will add this to docs asap.