有什么方法可以在Jenkins中构建输出更改时收到通知吗?

时间:2018-06-04 16:35:22

标签: jenkins

我正在使用Jenkins进行一些批处理工作。

当架子输出的输出与之前的版本不同时,我希望得到通知。

例如, 如果我在jenkins上运行以下bash shell,那么如果更改构建日期,则前一版本的输出将不同。

library(ggplot2)
library(grid)
library(gtable)

n_1 = 10
n_2 = 10
mean_1 = 5.5
sd_1 = 1
mean_2 = 7
sd_2 = 1
data = data.frame(y = c(
  rnorm(n_1, mean_1, sd_1),
  rnorm(n_2, mean_2, sd_2)
),
group = c(rep("1", n_1), rep("2", n_2)))
data$y[data$y > 10] <- 10
data$y[data$y < 0] <- 0

plots <- lapply(c("1", "2"), function(x) {
  ggplotGrob(
    ggplot(data[data$group == x,], aes(y)) +
      geom_histogram(
        breaks = seq(0, 10, length.out = 12),
        fill = ifelse(x == "1", "blue", "red"),
        colour = "black",
        alpha = .2
      ) +
      theme_classic() +
      theme(axis.title.x = element_blank()) +
      ylab(x) +
      scale_x_continuous(expand = c(0, 0), limits = c(0, 10)) +
      scale_y_continuous(expand = c(0, 0), limits = c(0, 4))
  )

})

gt <- gtable_matrix(
  "histograms",
  matrix(plots, nrow = 2, byrow = TRUE),
  widths = unit(1, "null"),
  heights = unit(c(1, 1), "null")
)

left <- textGrob("Frequency", rot = 90, just = c(.5, .5))
gt <-
  gtable_add_cols(gt, widths = grobWidth(left) + unit(0.5, "line"), 0)
gt <- gtable_add_grob(
  gt,
  left,
  t = 1,
  b = nrow(gt),
  l = 1,
  r = 1,
  z = Inf
)

gt <- gtable_add_cols(gt, widths = unit(0.5, "line"))
grid.newpage()
grid.draw(gt)

pushViewport(viewport())

grid.lines(y = c(.05, .98),
           x = (.11 + (5 / 10 * .861)),
           gp = gpar(col = "red"))
popViewport()

build - #1

日期:2018-06-05

build - #2

日期:2018-06-05

build - #3

日期:2018-06-06

只有在执行结果与上一个结果不同时,才能收到电子邮件,冗余等通知,如上面的版本3所示? 如果你有一个可以实现这个功能的插件或Jenkins是否已经支持它,你能告诉我吗?

我非常感谢你的帮助。 :)

1 个答案:

答案 0 :(得分:0)

Don't know if there is a plugin but in pipeline it's possible. Get current build log with: currentBuild.rawBuild.getLog(number_of_lines) and then compare it with the previous build log: Jenkins.getInstance().getItemByFullName('build_name').getBuildByNumber(env.BUILD_NUMBER.toInteger() - 1).logFile.text

If they are not equal send email: emailext body: 'build produced a different output than previous', subject: 'notification', to: 'me@mail.com'