Jenkins Pipeline 获取shell 输出结果

 

示例:

stage("Jar Files Check") {
                    steps{
                        script{
                            smd5 = sh(script: "ssh $host md5sum $APP_SEND_PATH/datacenter-${projectname}.jar|awk '{print \$1}'", returnStdout: true).trim()
                            sh "echo 'smd5:' $smd5"

                            for ( HOST in HOSTS ){
                                stage("Md5 to ${HOST}"){
                                    dmd5 = sh(script: "ssh $host ssh ${HOST} md5sum $Deploy_PATH/datacenter-${projectname}.jar|awk '{print \$1}'", returnStdout: true).trim()
                                    sh "echo 'dcentermd5:' $dcentermd5"
                                    if ( smd5 == dmd5){
                                    
                                      sh "echo ${HOST} 传输完成 "
                                    
                                    }else{
                                        
                                        sh "echo ${HOST} Jar File 传输未完成"
                                        sleep 10
                                    }
                                }
                            }
                            
                        }
                    }
                }
标准输出
bianliang = sh returnStdout: true ,script: "<shell command>"
bianliang = result.trim()
bianliang = sh(script: "<shell command>", returnStdout: true).trim()


获取执行状态
bianliang = sh returnStatus: true ,script: "<shell command>"
bianliang = result.trim()
bianliang = sh(script: "<shell command>", returnStatus: true).trim()
sh '<shell command>; echo $? > status'
def bianliang = readFile('status').trim()

  

 

posted @ 2023-07-06 18:33  来自牧羊人  阅读(572)  评论(0编辑  收藏  举报