Cross-platform scripting with Jenkins

萝らか妹 提交于 2021-01-28 00:38:40

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/22462013/cross-platform-scripting-with-jenkins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!