我试图在构建后通过电子邮件发送文件的输出。内部版本更新文件file1.json。她是我的问题。构建后,我试图创建一个变量,该变量对应file1.json(正在运行),然后尝试通过emailext通过电子邮件发送该变量。
Stage {
stage('Build'){\
sh """
npm install // builds and update the value in json file
UUID="`cat file1.json`" //outputs the string inside file which is what I want
echo \$UUID //shows the value here
"""
emailext body: "$UUID", //need the value here
subject: "$currentBuild.currentResult-$JOB_NAME",
to: 'someone@test.com'
}
`
The error message is groovy.lang.MissingPropertyException: No such property: UUID for class: groovy.lang.Binding
at groovy.lang.Binding.getVariable(Binding.java:63)
at
答案 0 :(得分:2)
您可以使用returnStdout: true
步骤的选项sh()
来获取shell的输出。
stage('Build'){
script {
sh 'npm install' // builds and update the value in json file
UUID = sh (script: 'cat file1.json', returnStdout: true).trim()
emailext body: "$UUID", subject: "$currentBuild.currentResult-$JOB_NAME", to: 'someone@test.com'
}
}