gpt4 book ai didi

bash - 仅更改一条管道的 Jenkins shell

转载 作者:行者123 更新时间:2023-12-03 02:06:53 24 4
gpt4 key购买 nike

如何让 Jenkins 使用 Bash 而不是其 native shell 仅用于一个 Jenkins 管道/Jenkinsfile? “代理”可以帮助我做到这一点吗?

我编写了一个用于部署的 shell 脚本,但某些参数包含空格,这会通过丢失一些参数来弄乱我生成的结果命令。我发现如何通过将 Jenkins shell 类型全局配置为 Bash 来避免此问题。但是,当我更改全局 shell 类型时,使用 Jenkins docker 插件语法的其他 Jenkins 管道在 docker 容器中使用“sh”命令时会被破坏。我的解决方法是根据我想要运行的 Jenkins 构建来调整 shell 类型的全局设置。这是皇家皮塔饼。

最佳答案

我很不好意思地说我所需要的只是 shebang .

我的 Jenkinsfile 使用 Jenkin 的 sh command 运行自定义 (bash) shell 脚本,如下所示:

sh "./deploy.sh \"arg1\" \"arg 2\" \"arg3\""

为了强制 deploy.sh 在 Bash 中运行,deploy.sh 的内容需要包含 #!/bin/bash 在第一行,如:

#!/bin/bash
echo "deploy args: $@"

无论如何,我认为应该有一种方法来告诉 Jenkins 管道它应该使用特定设置运行,例如 sh=bash。

关于bash - 仅更改一条管道的 Jenkins shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52192641/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com