Store the console output of a build step execution in Jenkins pipeline

て烟熏妆下的殇ゞ 提交于 2019-12-06 04:49:46

问题


In my jenkins pipeline i use the "Execute shell command " to run my gradle build script. Now i want to check if the build has failed in which case i would like to read the console output, store it in a string and publish it to a slack channel. The code that i have tried goes as follows :

try {
    for (int i = 0 ; i < noOfComponents ; i++ ){
        component = compileProjectsWithPriority[i]
        node {       
            out = sh script: "cd /home/jenkins/projects/${component} && ${gradleHome}/bin/gradle build", returnStdout: true}
    }
}
catch (e){
    def errorSummary = 'Build failed due to compilation error in '+"${component}"+'\n'+"${out}"
    slackSend (channel: '#my_channel', color: '#FF0000', message: errorSummary)
}

However it does not even execute the shell script and also the console output is null. What is the right approach to do this.

Thanks in advance

来源:https://stackoverflow.com/questions/42786894/store-the-console-output-of-a-build-step-execution-in-jenkins-pipeline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!