pipeline {
agent { label 'your-node-label' }
stages {
stage('Run Tests') {
steps {
script {
try {
// Your Selenium test execution command or script here
sh 'your-selenium-test-command-or-script.sh'
} catch (Exception e) {
echo "Node disconnected! Waiting for node to come back online..."
nodeWait()
echo "Node is back! Resuming test execution..."
// Retry the Selenium test execution command or script here
sh 'your-selenium-test-command-or-script.sh'
}
}
}
}
}
}
def nodeWait() {
// Wait for the node to come back online, check its status every 10 seconds
timeout(time: 30, unit: 'SECONDS') {
waitUntil {
return isNodeOnline()
}
}
}
def isNodeOnline() {
// Check if the node is online
def node = Jenkins.getInstance().getNodeByFullName('your-node-name')
return node != null && node.toComputer() != null && node.toComputer().isOnline()
}
1条答案
按热度按时间xoshrz7s1#
您可以使用“节点跟踪器”插件。这个插件允许Jenkins跟踪断开连接的节点,并在节点再次可用时自动恢复构建。
如果Node Stalker插件不能满足您的需求,或者您更喜欢其他方法,您可以使用Jenkins Pipeline和Groovy Script实现自定义解决方案。
字符串