binhuang01 / FeiShu-Notification

Jenkins 构建消息-飞书通知插件
MIT License
8 stars 6 forks source link

pipline方式和无法获取构建状态 #2

Closed fency12 closed 1 year ago

fency12 commented 1 year ago

pipline脚本式如下: stages { stage('测试成功失败') { steps { sh 'echo 不能失败啊' } } stage('发送飞书消息') { steps { FeiShu(webhook:'https://open.feishu.cn/open-apis/bot/v2/hook/xxxxxx8',proxy:'',msg:'',type:'',atAll:false) // 下面失败和成功上面都会通知 } } }

执行结果如下图:

图片 图片

问题: 1、pipline通知到jenkins如法获取构建状态? 2、如果上面的stage内的steps构建失败,下面的通知并不会执行,这个如何解决?

fency12 commented 1 year ago
stages {
    stage('测试成功失败') {
        steps {
            sh 'echo 不能失败啊'
        }
    }
    stage('发送飞书消息') {
        steps {
            FeiShu(webhook:'https://open.feishu.cn/open-apis/bot/v2/hook/xxxxxc8',proxy:'',msg:'',type:'',atAll:false)
            // 下面失败和成功上面都会通知
        }
    }
}
binhuang01 commented 1 year ago

如果使用声明式语法,请在stages代码块后面添加post后置块显式指定捕获错误,例如 post { failure { FeiShu(webhook:'',proxy:'',message:'',atAll:false) } }

如果想要获取流水线某个阶段的构建状态,应该用warn(需要jenkins版本较新)或catchError块包起来,例如 catchError(message:'xxx',buildResult:'failure',stageResult:'unstable') { FeiShu(webhook:'',proxy:'',message:'',atAll:false) }

fency12 commented 1 year ago

好的已解决。谢谢大佬