詹金斯:如何测试奴隶
Jenkins: how to test the slaves
我正在创建 Jenkins 作业列表以对我们的 Jenkins 构建环境进行完整性测试。我想创造多层工作。第一层工作将检查环境,例如如果所有的slave都启动了,那么第2层可以检查与其他工具的集成,如GitHub、TFS、SonarQube,然后第3层可以运行一些典型的构建项目。此完整性测试还可用于在对 Jenkins 服务器进行任何重大更改后验证环境。
我们在两台服务器上创建了大约 10 个从站,一个 Windows 和一个 Linux。我知道我可以在特定的从站上创建一个 运行 的工作,因此测试从站是否在线,但是这样我需要创建 10 个工作来测试所有的从站。有没有最好的方法来检查是否所有的奴隶都在线?
一种选择是使用 Jenkins Groovy 脚本来完成这样的任务。 Groovy plugin provides the Jenkins Script Console (a useful way to experiment) and the ability to run groovy scripts as build steps. If you're going to use the Script Console for periodic maintenance, you'll also want the Scriptler plugin 允许您管理您 运行 的脚本。
从 Manage Jenkins -> Script Console,你可以编写一个 groovy 脚本来遍历从站并检查他们是否在线:
for (node in Jenkins.instance.nodes) {
println "${node.name}, ${node.numExecutors}"
def computer = node.computer
println "Online: ${computer.online}, ${computer.connectTime} (${computer.offlineCauseReason})"
}
完成基本检查后,您可以在 Scriptler 中创建一个独立的脚本,或者为 运行 这些定期检查创建一个特殊的构建。
找出要检查的正确属性集通常需要一些迭代。正如我在 中所描述的,您可以编写函数来内省可用于脚本编写的对象。因此,通过反复试验,您可以开发一个脚本来执行您想要 运行 的检查。
我正在创建 Jenkins 作业列表以对我们的 Jenkins 构建环境进行完整性测试。我想创造多层工作。第一层工作将检查环境,例如如果所有的slave都启动了,那么第2层可以检查与其他工具的集成,如GitHub、TFS、SonarQube,然后第3层可以运行一些典型的构建项目。此完整性测试还可用于在对 Jenkins 服务器进行任何重大更改后验证环境。
我们在两台服务器上创建了大约 10 个从站,一个 Windows 和一个 Linux。我知道我可以在特定的从站上创建一个 运行 的工作,因此测试从站是否在线,但是这样我需要创建 10 个工作来测试所有的从站。有没有最好的方法来检查是否所有的奴隶都在线?
一种选择是使用 Jenkins Groovy 脚本来完成这样的任务。 Groovy plugin provides the Jenkins Script Console (a useful way to experiment) and the ability to run groovy scripts as build steps. If you're going to use the Script Console for periodic maintenance, you'll also want the Scriptler plugin 允许您管理您 运行 的脚本。
从 Manage Jenkins -> Script Console,你可以编写一个 groovy 脚本来遍历从站并检查他们是否在线:
for (node in Jenkins.instance.nodes) {
println "${node.name}, ${node.numExecutors}"
def computer = node.computer
println "Online: ${computer.online}, ${computer.connectTime} (${computer.offlineCauseReason})"
}
完成基本检查后,您可以在 Scriptler 中创建一个独立的脚本,或者为 运行 这些定期检查创建一个特殊的构建。
找出要检查的正确属性集通常需要一些迭代。正如我在