XShell Plugin

Plugin Information

Plugin ID xshell
Latest Release 0.4
Latest Release Date Sep 22, 2010
Plugin Central Plugin Central 3.2
Sources Subversion
Support Eclipse Hudson Forum
Issue Tracking Eclipse Bugzilla
Hudson Core (latest) 3.3.3

This plugin defines a new build type to execute a shell command in a cross-platform environment.

Description

Cross platform shell executor.

Using Hudson built-in "Execute Windows batch command" you can run commands using the windows shell.

Using Hudson built-in "Execute shell" you can run commands using unix shell.

If you need to run a job cross platform you cannot use the two standard executors provided by Hudson. You need a "build step" that can be executed both in Windows and in Unix.

This plugin does exactly this: it takes a command, as the two standard build steps do, and executes it calling the correct shell depending on the operating system running on the current job executor.

What it does...

  • It runs any executable (with complete command line) available in the system from current working dir (command must be in Path or in job's workspace directory or subdirectory).
  • Automatic conversion of file separator is done according to the executing operating system.

Constraints:

  • the current working directory of the command execution is always the job's workspace root.
  • ./ must not be included in command line (use the configuration switch provided to specify that command is in current working dir or subdir).

Examples:

Example 1: run executable + script
php scripts/build.php

runs php (must be in Path) with scripts/build.php as argument (path relative to workspace; forward slashes can be used because php handles them correctly in any OS).

this command is equivalent to the following

php scripts\build.php

The file separator will be automatically translated to the right one, according to the operating system running during execution.

... and what it does not!

Command translation problem

Description

It cannot translate any command! So you cannot write

rm -rf bin

because on windows rm command is not available.

Solution

You can wrap your commands in two scripts, one for windows and one for unix, each one calling the right command for the operating system:

clean
rm -rf bin
clean.bat
del /F /S bin

and then call clean using an XShell build step.
This will execute clean in unix and clean.bat in windows.

Variable expansion problem

Description

Translate variable expansion syntax in the command line provided to the plugin. So you want to write something like this:

myscript $JOBPARAM1

or

myscript %JOBPARAM1%

This won't work because each of this command will only work in one OS, not in both.

Solution

You can wrap your commands in two scripts, one for windows and one for unix, each one calling the right command for the operating system:

script-wrapper
myscript $JOBPARAM1
script-wrapper.bat
myscript %JOBPARAM1%

and then call script-wrapper using an XShell build step.
This will execute script-wrapper in unix and script-wrapper.bat in windows.

Notes

  • in windows you can call clean and get clean.bat called, in unix you can't (so the solutions above work);
  • in unix you have to specify if the command is in the current working dir (and if it is not available it will not be searched in PATH), in windows you haven't to.

Build step configuration

To add a XShell build step

  • click on the Add build step button and choose Invoke XShell script;
  • fill in the command line text;
  • choose if the executable is in global Path or in workspace.

TODO

  • Allow execution from a custom working dir (different from workspace dir)
  • Run executable from workspace directory (in unix must be written using ./ form). DONE in 0.2
  • Replace any '\' or '/' in the command line with File.separator
  • Set environment variables... (see comments)

Version history

0.5 (Development)

0.4 (09/22/2010)

  • Modified regex for path separator replacement that was causing an exception issue #7538
  • Added build variables to environment variables (as in CommandInterpreter).

0.3 (05/18/2010)

  • Replace any '\' or '/' in the command line with correct file separator (selected using OS where the task is executed).

0.2 (03/26/2010)

  • Run executable from workspace directory also in unix.

0.1 (03/25/2010)

Initial release

  • Runs a single command line

Labels:

plugin-builder plugin-builder Delete
Enter labels to add to this page:
Wait Image 
Looking for a label? Just start typing.
  1. May 17, 2010

    Axel Heider says:

    Could you add these things: "run from sub-directory", where slashes are conver...

    Could you add these things:

    • "run from sub-directory", where slashes are converted automatically
      I have a workspace where the following scripts should run: foo/bar/doItAll, foo/bar/doItAll.bat.
      If I give "foo/bar/doItAll", the linux build works, but windows gives this:
         [trunk] $ cmd.exe /C '"foo/bar/doItAll && exit %%ERRORLEVEL%%"'
         command not found
         Finished: FAILURE
    • set environment varienbles for all axises in matrix builds, like in "Execute Windows batch command" and "Execute shell"
      Exmaple: AXIS1=[alpha,beta], AXIX2=[foo,bar]. in the scripts, the variables AXIS1 and AXIX2 should be set.
    1. May 15, 2010

      Marco Ambu says:

      Hi, I have changed the plugin to replace '\' and '/' with File.separator. I gu...

      Hi,

      I have changed the plugin to replace '\' and '/' with File.separator.

      I guess this should be enough to solve your first problem... about the second... maybe it will take some more time.

      1. May 17, 2010

        Axel Heider says:

        Thanks. Does ist also convert the slashes the other way, ie "/" to "\"?

        Thanks. Does ist also convert the slashes the other way, ie "/" to "\"?

        1. May 18, 2010

          Marco Ambu says:

          Yes, it works in both ways. I have released 0.3 with this modification included...

          Yes, it works in both ways.

          I have released 0.3 with this modification included. I have tried it in my test installation, can you try it and report any problem or other suggestion? Thanks.

    2. Sep 22, 2010

      Marco Ambu says:

      I have added the build variables to the environment variables; if the variables ...

      I have added the build variables to the environment variables; if the variables added in a matrix project are 'build variables' maybe we have solved the issue you reported (2nd item in your comment).

  2. Sep 22, 2010

    Sorin Sbarnea says:

    I suspect that this plugin is borken, see http://issues.hudson-ci.org/browse/HUD...

    I suspect that this plugin is borken, see http://issues.hudson-ci.org/browse/HUDSON-7538

    I tried to assign the bug to the `xshell` component but there is no component with this name.