gpt4 book ai didi

linux - 在 Jenkins 管道上运行 bash 命令

转载 作者:IT老高 更新时间:2023-10-28 12:40:15 30 4
gpt4 key购买 nike

在 groovy 脚本中(用于 jenkins 管道):如何运行 bash 命令而不是 sh 命令?

我尝试了以下方法:

sh 调用中调用“#!/bin/bash”:

stage('Setting the variables values') {
steps {
sh '''
#!/bin/bash
echo "hello world"
'''
}
}

sh 调用替换为 bash 调用:

stage('Setting the variables values') {
steps {
bash '''
#!/bin/bash
echo "hello world"
'''
}
}

其他信息:

我的命令比 echo hello world 更复杂。

最佳答案

您提供的 Groovy 脚本将生成脚本中的第一行格式化为空行。告诉脚本使用/bin/bash 而不是/bin/sh 运行的 shebang 需要位于文件的第一行,否则将被忽略。

因此,您应该像这样格式化 Groovy:

stage('Setting the variables values') {
steps {
sh '''#!/bin/bash
echo "hello world"
'''
}
}

它将使用/bin/bash 执行。

关于linux - 在 Jenkins 管道上运行 bash 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44330148/

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