Jenkins的跨平台脚​​本编写 [英] Cross-platform scripting with Jenkins

查看:108
本文介绍了Jenkins的跨平台脚​​本编写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在组织中经常使用Jenkins,用于构建和部署项目.我有一组经过微调的bash脚本,它们可以模块化并且可用于多个项目.这些是由Jenkins在部署作业期间触发的.

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.

当部署环境从Linux更改为Windows时,就会出现问题.bash脚本不再是一个选项(在多个/随机部署计算机上安装cygwin也不是一个选择).我可以批量重写所有bash脚本,但这将导致双重维护,并且微小的错误会渗入任何一个环境.

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.

我正在寻找的是一种跨平台的功能,可以编写部署脚本,而Jenkins可以立即支持这些功能,而无需在目标环境上预先安装某些功能.想到ANT是因为Jenkins可以在Windows或Linux上运行Ant而不需要安装任何东西,但是按照定义为声明性"语言的定义,Ant缺少了我编写部署脚本所需的一切.

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.

我有什么选择?

推荐答案

不幸的是,没有本机跨平台脚本语言.但这并不意味着我们不能共同破解我们自己的糟糕解决方案.例如混合型Bastch或Batsh ...

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...

混合A:

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

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

混合B:

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

#Bash
echo Hello World
exit 0

这仍然需要逻辑上的重复,但是至少它们共享同一文件.请注意,扩展名必须为.bat或.cmd,文件才能在Windows上正确运行.

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.

这篇关于Jenkins的跨平台脚​​本编写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆