终止在詹金斯管道脚本中以背景运行的过程
我有一个声明性的詹金斯管道,该管道使用脚本步骤在循环中执行两件事:
- 通过在后台运行bash脚本打开SSH隧道(在末尾添加
&
在末尾) - 做其他一些事情在让SSH隧道打开问题时,
pipeline {
stage('some stage') {
steps {
script {
def hosts = ['host-0.service.consul', 'host-1.service.consul', 'host-2.service.consul']
for (host in hosts){
// kill previously opened tunnel here if it has been opened
???
// run script in background
sh "./scripts/myscript.sh &"
// do some other stuff
...
}
}
}
}
}
}
问题是,在每次迭代时,我必须通过杀死用sh的过程来关闭SSH隧道。但是,我不知道该过程的基础。
我该如何使用Groovy和/或Bash在Jenkins管道中进行此操作?
不确定这个问题是否与Bash或Jenkins/Groovy有关
I have a declarative Jenkins pipeline that uses a script step to do two things inside a loop:
- opening an SSH tunnel by running a bash script in the background (adding
&
at the end) - do some other stuff while having the SSH tunnel open
pipeline {
stage('some stage') {
steps {
script {
def hosts = ['host-0.service.consul', 'host-1.service.consul', 'host-2.service.consul']
for (host in hosts){
// kill previously opened tunnel here if it has been opened
???
// run script in background
sh "./scripts/myscript.sh &"
// do some other stuff
...
}
}
}
}
}
}
The problem is that upon each iteration I have to close the SSH tunnel by killing the process spawned with sh "./scripts/myscript.sh &"
. However I don't know the PID of that process.
How can I do this inside a Jenkins pipeline using Groovy and/or Bash?
Not sure if this question is more related to bash or to Jenkins/Groovy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论