使用 Jenkins 进行跨平台脚本编写 [英] Cross-platform scripting with Jenkins

查看:30
本文介绍了使用 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天全站免登陆