请帮助我如何保存到文件构建作业属性尝试在下面的方式,我得到以下文本文件:[slave:org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper@7fb29d4c]
def jobsResult = [:]
pipeline {
agent { label 'Apps' }
stages {
stage('Exec Job')
steps {
script {
echo "Stage name is : ${STAGE_NAME}"
try {
jobsResult.job_01 = build job: "job_01", propagate: true, wait: true
jobsResult.job_02 = build job: "job_02", propagate: true, wait: true
}
catch (e) {
echo "Slave job failed, marking build as UNSTABLE"
currentBuild.result = 'UNSTABLE'
}
writeFile file: "jobsResults.txt", text: "${jobsResult}"
}
}
}
stage('Sleep') {
steps {
script {
echo "Stage name is : ${STAGE_NAME}"
try {
sleep 10
} catch (Exception e) {
echo "Sleep stage failed, but continuing..."
}
}
}
}
}
}
1条答案
按热度按时间yzuktlbb1#
当您使用
jobsResult
的字符串表示写入文件,即[slave:org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper@7fb29d4c]
您应该使用
writeJSON
,它会将map对象序列化为JSON并写入文件由于
writeJSON
只适用于Map对象,您可能需要将对象转换为Map,以便您可以成功地将数据保存到文件中。一个可能的解决方案是定义以下方法ref
然后将下面的行从
到