No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GerritPipelineComment.groovy 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package org.wikimedia.integration
  2. /**
  3. * Gerrit revision that can be used to comment on a gerrit patchset
  4. *
  5. * {@code
  6. * import org.wikimedia.integration.GerritReview
  7. * import org.wikimedia.integration.GerritPipelineComment
  8. *
  9. * stage('comment') {
  10. * comment = new GerritPipelineComment(
  11. * jobName: xx,
  12. * buildNumber: xx,
  13. * jobStatus: xx,
  14. * image: xx,
  15. * tags: xx
  16. * )
  17. * GerritReview.post(this, comment)
  18. * }
  19. */
  20. class GerritPipelineComment extends GerritComment implements Serializable {
  21. /**
  22. * Name of the job
  23. */
  24. String jobName
  25. /**
  26. * Jenkins build number
  27. */
  28. String buildNumber
  29. /**
  30. * Image in the docker registry
  31. */
  32. String image
  33. /**
  34. * Build status
  35. */
  36. String jobStatus
  37. /**
  38. * Image tags
  39. */
  40. List<String> tags
  41. String formatDashboard() {
  42. "pipeline-dashboard: ${this.jobName}"
  43. }
  44. String formatResult() {
  45. "pipeline-build-result: ${this.jobStatus} (job: ${this.jobName}, build: ${this.buildNumber})"
  46. }
  47. String formatImage() {
  48. "IMAGE:\n ${this.image}"
  49. }
  50. String formatTags() {
  51. "TAGS:\n ${this.tags.join(', ')}"
  52. }
  53. /**
  54. * Format final message output
  55. */
  56. String formatMessage() {
  57. def msg = "${this.formatDashboard()}\n${this.formatResult()}\n"
  58. if (this.image != null) {
  59. msg = "${msg}\n${this.formatImage()}\n"
  60. }
  61. if (this.tags != null) {
  62. msg = "${msg}\n${this.formatTags()}\n"
  63. }
  64. msg
  65. }
  66. GerritPipelineComment(Map settings = [:]) {
  67. settings.each { prop, value -> this.@"${prop}" = value }
  68. }
  69. }