我有一个 Jenkins 声明式管道,我在一个阶段进行构建,并在另一阶段在不同的机器上进行测试。我还有一个 Selenium 集线器与 Jenkins master 在同一台机器上运行。
pipeline {
agent none
stages {
stage('Build') {
agent { node { label 'builder' } }
steps {
sh 'build-the-app'
stash(name: 'app', includes: 'outputs')
}
}
stage('Test’) {
agent { node { label 'tester' } }
steps {
unstash 'app'
sh 'test-the-app'
}
}
}
}
我希望在测试阶段运行的 Selenium 测试能够连接回 Jenkins 主计算机上的 Selenium 集线器,这意味着我需要从从属计算机获取 Jenkins 主计算机的 IP 地址或主机名。
有没有办法做到这一点? Jenkins master URL/主机名不在环境变量中,我不确定如何获取 Jenkins master 的 IP 地址。
不确定是否有更好的方法来做到这一点,我可以运行
def masterIP = InetAddress.localHost.hostAddress
println "Master located at ${masterIP}"
在我的詹金斯文件中。我第一次在 Jenkinsfile 中运行此代码时,构建失败并显示
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException:
Scripts not permitted to use method java.net.InetAddress getHostAddress
at org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.StaticWhitelist.rejectMethod(StaticWhitelist.java:178)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor$6.reject(SandboxInterceptor.java:243)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:363)
at org.kohsuke.groovy.sandbox.impl.Checker$4.call(Checker.java:241)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:238)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:28)
我必须通过导航到批准 Jenkins 中的方法签名Manage Jenkins
> In-process Script Approval
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)