Running Ruby script checks on Windows agents

Hey! I’m forwarding some discussion that showed up on a github ticket, that I think would best suited to open up to the community forum. Are there people here with experience running ruby check commands on Windows that can provide some pointers?

Hey guys,

I’ve recently faced an interesting issue that I thought you can advise me about. I’m trying that the agent could run a check command which consists only of a Ruby script name without invoking the ruby interpreter explicitly. e.g. ‘script.rb’. On platforms other than Windows, this can be done by adding a shebang in the beginning of the script (and making sure that the script is located at a directory which is included in the PATH env var, which I did for all agents on all platforms), but of course on Windows this doesn’t exist.

I’ve tried 4 approaches and with each one I faced several issues:

defining a file association on the Windows machine running the agent on the machine level, which affects all users that don't have their own file association and might override any previous association made.

defining a file association only for the user which runs the agent, which isn't really good in case a domain user runs the agent because the association defined in a domain user registry hive will follow him across all computers in this domain (at least this is what I understood).

creating a batch script with the same name as the Ruby script ('script.rb' gets a batch called 'script.rb.bat') that invokes the interpreter directly with the arguments given to the batch file. This failed because when both are at the same path, running 'script.rb' runs the Ruby script, which of course won't work without the file association.

I tried taking the command that was sent to the agent for execution, splitting it (by whitespaces) and prefixing each element that is suffixed by '.rb' with the ruby interpreter path, but this approach has lots of special cases (implement deqouting and other special cases) and on Windows this means that I will have to convert 'script.rb' to to the full path to the script, which also requires code to search for the script inside all PATH directories (and maybe other directories) and thus finding the full path to the script.

I need this because I want the same exact commands (Ruby scripts) to be executed by Windows agents and agents running on other platforms.

Did you guys ever face this issue? and if yes can you recommend an approach to deal with this?

Thanks,

David

Trying to reply based on my limited Windows + Ruby knowledge.

See if the ruby interpreter you have installed on Windows supports the ‘-S’ argument

ruby --help
-S             Makes Ruby use the PATH environment variable to search for script, unless its name begins with a slash.  This is used to emulate #! on machines that don't support it, in the following manner:

If so you can use commands like ruby -S example-check.rb on all your systems