jenkinsci / google-chat-notification-plugin

Google Chat Notification Jenkins Plugin to send build status
https://plugins.jenkins.io/google-chat-notification/
MIT License
39 stars 20 forks source link

Encoding #16

Closed Redirts closed 1 year ago

Redirts commented 5 years ago

Does this plugin support encoding?

I want to send to Google chat, text that contains accents (i.e. test message José Caniço) but the message arrives in Google Chat as:

test message Jos Cani o

Here is my jenkinsfile setup:

```
stages{
    stage("Checkout"){
        steps{
            checkout scm

            script {
                // extract author name, committer name, and commit message of GIT_COMMIT
                author_name = sh(script: "git log -n 1 ${env.GIT_COMMIT} --format=%aN", encoding: 'UTF-8', returnStdout: true).trim()
                committer_name = sh(script: "git log -n 1 ${env.GIT_COMMIT} --format=%cN", encoding: 'UTF-8', returnStdout: true).trim()
                commit_message = sh(script: "git log -1 --format=%B ${GIT_COMMIT}", encoding: 'UTF-8', returnStdout: true).trim()
                echo "Commiter: ${author_name} - Mensagem: ${commit_message}"
            }
        }

... post{ failure{ emailext attachLog: true, body: 'Your build failed! \nFix it or the dolphins will come and get you: ${BUILD_URL} \nYou can see your screw up in the attached log!', recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']], subject: currentBuild.currentResult + " : " + env.JOB_NAME, compressLog: true googlechatnotification url: 'https://chat.googleapis.com/v1/spaces/AAAACc4dhDQ/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=3jZ2v-MfYlYQApdUGSsBObgaTLl-MCXOdZTJYuRg_EI%3D', message: "User: ${author_name} broke " + env.JOB_NAME + " jenkins build! \nUser commit message: ${commit_message} \nURL: ${BUILD_URL}", notifyAborted: 'true', notifyFailure: 'true', notifyNotBuilt: 'true', notifySuccess: 'false', notifyUnstable: 'true', notifyBackToNormal: 'true', suppressInfoLoggers: 'true', sameThreadNotification: 'true' } }



Initially I thought it was setup issue with jenkins itself but the echo command above prints out the text fine.

Any ideia?
joaorebelo-ar commented 5 years ago

I have been having the same issue with similar chars. Do you any clues?

Redirts commented 5 years ago

No :-(

joaorebelo-ar commented 5 years ago

I believe that the bug might lie somewhere in CommonUtil.java#call.. I have tried using a rest client to post the same content and it worked.

curl -X POST -k -H 'Content-Type: application/json' -i '' --data '{ "text": "The pipeline marketdatafeed » first-version #54 completed successfully. João Rebelo you may proceed."}'

joaorebelo-ar commented 5 years ago

Add a look at a possible solution for this and ended up in SO: how-to-encode-russian-text-in-post-request-using-apache-httpclient

hgmart commented 4 years ago

I think perhaps in the following lines an encoding could be defined. Perhaps exists some method like post.SetEnconding("UTF-8") or something to add to the header the 'content-charset'.

https://github.com/jenkinsci/google-chat-notification-plugin/blob/ffacf6a78dc8b37d5e85dde90d8f17fa092be3a6/src/main/java/io/cnaik/service/CommonUtil.java#L179

In there something like Replacing the Content-Type to "application/json;charset=UTF-8"

https://github.com/jenkinsci/google-chat-notification-plugin/blob/ffacf6a78dc8b37d5e85dde90d8f17fa092be3a6/src/main/java/io/cnaik/service/CommonUtil.java#L192