Jenkins 声明式管道添加 groovy postbuild 脚本

Jenkins declarative pipeline add groovy postbuild script

我有 groovy postbuild 脚本

def error = manager.getLogMatcher(".*(Error:(.*)))
if(error?.matches()) {
    manager. addShortText(matcher.group(1))
}

现在我正在尝试将其转换为声明性管道语法

pipeline{
    post{
       failure{}
    }
}

所以我可以在失败选项卡中添加 groovy 脚本吗?或者我必须添加阶段?我看到有 jenkins-badge-plugin 但不确定如何添加正则表达式来查找文本然后添加 batch

您只需要在失败中添加脚本块,如下所示,您可以将 post 构建 groovy 脚本放在那里:

pipeline{
    post{
       failure{
           script{
             //Add your post build script code in case of failure
           }
       }
    }
}