1
我有一个脚本正在作为jenkins管道执行,它工作正常。我想在多个环境中重复使用它,所以我将所有代码移到了函数中,并从多个文件中加载它们。在Jenkinsfile中使用加载的脚本
库文件 - 健康检查:
#!groovy
@NonCPS
def check(type) {
stage "prepare"
echo "TEST1"
props = readProperties file:'build.properties'
echo "TEST2"
stage "queues"
checkQueues()
}
@NonCPS
def checkQueues() {
txt = "http://ltxl0207.sgdcelab.sabre.com:8161/api/jolokia/read/org.apache.activemq:brokerName=localhost,destinationName=!/tss!/trip_source_updates,destinationType=Queue,type=Broker/QueueSize".toURL().getText(requestProperties: [Authorization: "Basic " + "admin:admin".getBytes().encodeBase64().toString()])
json = new groovy.json.JsonSlurper().parseText(txt)
echo "Got response: " + txt
}
return this;
文件使用它 - 健康检查-dev的:
#!groovy
node {
checkout scm
healthcheck = load 'Healthcheck'
healthcheck.check('DEV')
}
而且麻烦的是剧本没有得到通过readProperties
和准备阶段就停在那里,无视排队阶段:
[Pipeline] load
[Pipeline] { (Healthcheck)
[Pipeline] }
[Pipeline] // load
[Pipeline] stage (prepare)
Entering stage prepare
Proceeding
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
我在做什么错?当我将代码移动到单个文件时,它可以正常工作。
我对这些文件使用相同的回购,他们坐在旁边。 –
你试图读取属性的'build.properties'文件如何?您正在使用'checkout scm',但是包含groovy脚本的初始工作空间和包含'build.properties'文件的签出工作空间可能并不相同,因此导致您的属性文件找不到。 您可以尝试从'$ {projectWorkspace} @ script/build.properties'访问您的属性文件吗? – Pom12
但是为什么当我只有一个Healthcheck文件时它工作? '结帐scm'需要构建工作(它需要签出完整的git回购) –