Question

I use Jenkins a lot within our organization, for building and deploying projects. I have a set of bash scripts fine-tuned to be modular and reusable for multiple projects. These are triggered by Jenkins during deploy jobs.

The problem comes when the deployment environment changes from Linux to Windows. The bash scripts are no longer an option (installing cygwin on multiple/random deployment machines is also not an option). I could rewrite all the bash scripts in batch, but that would result in dual-maintenance and tiny bugs slipping into either of the environments.

What I am looking for is a cross-platform ability to write deployment scripts, and something that Jenkins can support out of the box, without having to pre-install something on the target environment. ANT comes to mind as Jenkins can run Ant on either Windows or Linux without having to install anything, but by the very definition as a "declarative" language, Ant is missing everything that I need to write a deployment script.

What are my alternatives?

Was it helpful?

Solution

There are unfortunately no native cross-platform scripting languages. But that does not mean we cannot hack together our own terrible solution. Such as a hybrid Bastch or Batsh...

Hybrid A:

date > /dev/null # >nul <nul & goto Batch
#Bash
echo Hello World
exit 0

:Batch
@echo off
echo Hello World
exit /b 0

Hybrid B:

: '"
:: Batch
@echo off
echo Hello World
exit /b 0
"'

#Bash
echo Hello World
exit 0

This still requires duplication of logic, but at least they share the same file. Note that the extension must be .bat or .cmd for the files to run correctly on Windows.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top