我有一个作为詹金斯管道执行的脚本,它运行良好。我想在多个环境中重用它,所以我将所有代码移动到函数并从多个文件中加载它们。
库文件 -健康检查:
#!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;
使用它的文件 - Healthcheck-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
我做错了什么?当我将代码移动到单个文件时,它可以正常工作。