jenkinsci / office-365-connector-plugin

Office 365 Connector plugin sends jobs status notifications to Microsoft Teams or Outlook
https://plugins.jenkins.io/Office-365-Connector/
Apache License 2.0
87 stars 82 forks source link

Display build status with Section.activityImage instead of Card.themeColor #336

Open AceOfSnakes opened 5 months ago

AceOfSnakes commented 5 months ago

What feature do you want to see added?

Colleagues - what are you thinking about display status of the build in the Section.activityImage (missed for now) instead of Card.themeColor

Image source should be in format img src="data:image/png;base64; *****

where ***** is a base64 of a image content - for CORS workaround in teams

teamz blue gray green red yellow

Upstream changes

No response

Are you interested in contributing this feature?

No response

damianszczepanik commented 5 months ago

Can you clearly show images with version before the change (current implementation) and new one (proposal)?

AceOfSnakes commented 5 months ago

Hi first image is a a real result of submit in teams with Section.activityImage teamz latest version

AceOfSnakes commented 5 months ago

as you see on my first screenshot - border is gray before changes on microsoft side all works - now all broken image

AceOfSnakes commented 5 months ago
As designed With Jenkins plugin With generic webhook connection
teams webhook
Now With Jenkins plugin With generic webhook connection
image image
Proposed. Real screenshots with Jenkins 2.426.3 LTS in both cases With Jenkins plugin With generic webhook connection
image image
damianszczepanik commented 5 months ago

as you see on my first screenshot - border is gray before changes on microsoft side all works - now all broken image

This one is supported by additional the plugin that was not supported from quite long - that could be a problem as well

damianszczepanik commented 5 months ago

Ok, so what is the goal for this change? Are you going to avoid having button 'show more' ? What the Jenkins logo come from ?

AceOfSnakes commented 5 months ago

The goal of this change is to display build status with jenkins logo. Images stored in plugin resources and transfer in message body. Build started : blue logo Success : green logo Aborted : gray logo Unstable : yellow logo Failed: red logo All other fuhctiionality unchaged.

"activityImage": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAABg2lDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AcxV9Ti........"

image

looks like developers of MS teams after adding theme change in teams no more use "themeColor": "#CC0003" in any cases

damianszczepanik commented 5 months ago

I don't see value of having Jenkins logo with colors. I don't want to maintain images here. There is clear information about build status and having additional fancy logo does not bring any value

martens-d commented 5 months ago

The elephant in the room is, that M$ will stop the support for the old MessageCards. I tested the newer AdaptiveCard. The Jenkins plugin does not support that. But if you use Incoming Webhook connector I was able to post AdaptiveCards.

They support "colors" sort of and do not fold up. I use a shared lib for messages to teams and I do it like this:

def payload = """{
  "type": "message",
  "attachments": [
    {
      "contentType": "application/vnd.microsoft.card.adaptive",
      "contentUrl": null,
      "content": {
        "type": "AdaptiveCard",
        "\$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
        "version": "1.6",
        "msteams": { "width": "Full" },
        "body": [
          {
            "type": "Container",
            "style": "##STATUS##",
            "bleed": true,
            "items": [
              {
                "type": "RichTextBlock",
                "inlines": [
                  {
                    "type": "TextRun",
                    "text": "Nachricht von ${env.JOB_BASE_NAME}",
                    "size": "Large",
                    "weight": "bolder"
                  }
                ]
              }
            ]
          },
          {
            "type": "Container",
            "items": [
              {
                "type": "RichTextBlock",
                "inlines": [
                  {
                    "type": "TextRun",
                    "text": "##MESSAGE##"
                  }
                ]
              }
            ]
          },
          {
            "type": "FactSet",
            "facts": [
              "##FACT##"
            ]
          }
        ]
      }
    }
  ]
}"""

    def payload_fact = """{
              "title": "##TITEL##",
              "value": "##VALUE##"
            }"""

...

switch ( Status ) {
      case "SUCCESS":
        status_color = "good";
        break; 
      case "UNSTABLE": 
        status_color = "warning";
        break; 
      case "FAILURE": 
        status_color = "attention";
        break; 
      case "NOT_BUILT": 
        status_color = "warning";
        break; 
      case "ABORTED": 
        status_color = "accent";
        break; 
      default: 
        status_color = "default";
        break;
    } 

def payload_factlist = payload_fact.replace("##TITEL##", "Status").replace("##VALUE##", "${Status}");

if (Facts != null)
    {
      Facts.eachWithIndex{ entry, index ->
        payload_factlist = payload_factlist + ',' + payload_fact.replace("##TITEL##", entry.key).replace("##VALUE##", entry.value)
      }
    }

    payload = payload.replace("##STATUS##", status_color).replace("##FACT##", payload_factlist);

httpRequest(authentication: CREDENTIALS,
                      quiet: !debug,
                      contentType: 'APPLICATION_JSON_UTF8',
                      httpMode: 'POST',
                      requestBody: payload,
                      url: Webhook);

using it like so:

office.sendStatusMessage(
          Status: currentBuild.result, 
          Message: "${JOB_NAME} - ${BUILD_DISPLAY_NAME}\nerfogreiche Freigabe mit Fehlern",
          Facts: [
            "Dauer": currentBuild.durationString.replace(' und läuft', ''),
            "Gestartet durch": currentBuild.getBuildCauses('hudson.model.Cause$UserIdCause').userName[0],
            "Fehler": "Die Programme konnten nicht erfolgreich compiliert werden."],
          Webhook: "...")

this is what it looks like: (it's in german mind, but you get the idea) grafik

Since I am only working with pipelines, this is no issue, but the plugin needs to be change in order for this to work with freestyle projects.

I even have another message type with an image (in the body of the ActiveCard):

         {
            "type": "Table",
            "columns": [
                {
                    "width": 1
                }
            ],
            "rows": [
                {
                    "type": "TableRow",
                    "cells": [
                        {
                            "type": "TableCell",
                            "bleed": true,
                            "items": [
                                {
                                    "type": "TextBlock"
                                }
                            ],
                            "style": "##COLOR##"
                        }
                    ]
                }
            ],
            "showGridLines": false,
            "firstRowAsHeaders": false
        },
        {
            "type": "Table",
            "bleed": true,
            "columns": [{"width": "60px"}, {"width": 1}],
            "rows": [
                {
                    "type": "TableRow",
                    "cells": [{
                            "type": "TableCell",
                            "items": [{
                                    "type": "Image",
                                    "url": "##IMAGE##",
                                    "style": "Person"
                                }],
                            "horizontalAlignment": "Center"
                        },
...

You can put an image as base64 there.