问题描述
我想在jenkins pipeline中运行bash命令,而不是在groovy脚本中使用shell命令:我已经尝试使用#!/ bin / bash :
stage('设置变量值'){
steps {
sh'''
#!/ bin / bash
echohello world
'''
}
}
此外,还尝试使用'bash'替代'sh'
stage('设置变量值'){
steps {
bash'''
#!/ bin / bash
echohello world
'' '
}
}
显然,我的命令比'echo hello world'。
所以,你应该像这样格式化你的Groovy:
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $'步骤{
bash'''#!/ bin / bash
echohello world
'''
}
}
它将以/ bin / bash执行。
I want to run a bash command in jenkins pipeline instead a shell command, inside a groovy script:
I already tried use "#!/bin/bash":
stage('Setting the variables values') {
steps {
sh '''
#!/bin/bash
echo "hello world"
'''
}
}
And also a tried to use 'bash' instead 'sh'
stage('Setting the variables values') {
steps {
bash '''
#!/bin/bash
echo "hello world"
'''
}
}
Obviously my command is complex than a 'echo hello world'.
The Groovy script you provided is formatting the first line as a blank line in the resultant script. The shebang, telling the script to run with /bin/bash instead of /bin/sh, needs to be on the first line of the file or it will be ignored.
So instead, you should format your Groovy like this:
stage('Setting the variables values') {
steps {
bash '''#!/bin/bash
echo "hello world"
'''
}
}
And it will execute with /bin/bash.
这篇关于在jenkins管道上运行bash命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!