Search code examples
jenkinsjenkins-pipelinemicrosoft-teams

Sending notifications to Microsoft Teams for Jenkins. [hostname in certificate didn't match] error


I have a problem sending the job notification at work, here I use the company's VPN and firewall. The Job runs successfully and it is possible to see in the log that the connector was activated, but the notification is not sent. If you use a manual curl with the message it works normal

 script {
                    final String url = "webhook"

                    final String response = sh(script: "curl -X POST -H 'Content-type:application/json' --data '{\"text\":\"Message sent by jenkins\"}' webhook", returnStdout: true).trim()

                    echo response
                }

enter image description here

but in an automated way by Jenkins it is not working

Follow the part of the office 365 pipeline:

post {
      failure {
        office365ConnectorSend webhookUrl: "$WEB_HOOK_URL",
                factDefinitions: [[name: "message", template: "Falha: Deploy em $DEPLOY_STAGE de $REPO"],
                                  [name: "status", template: "Falha"]],
                color: "#FF0000",
                status: "Failure"

        sh("curl -v --location --request POST '$WEB_HOOK_URL' --header 'Content-Type: application/json' --data-raw '{\"@type\": \"MessageCard\",\"@context\": \"http://schema.org/extensions\",\"themeColor\": \"#FF0000\",\"summary\": \"Teste de Mensagens EndPoint Jenkins\",\"sections\": [{\"activityTitle\": \"Jenkins avisa!\",\"activitySubtitle\": \"Resultado do build\",\"activityImage\": \"https://ac-buckets-dev-acpublicmedia-2cxkd4j0deg1.s3.amazonaws.com/icons/RedDownArrow.png\",\"facts\": [{\"name\": \"Message\",\"value\": \"FALHA: Deploy em $DEPLOY_STAGE de $REPO\"}, {\"name\": \"Status\",\"value\": \"Failure\"},{\"name\": \"Job\",\"value\": \"${JOB_NAME}:${BUILD_NUMBER}\"}],\"markdown\": true}],\"potentialAction\": [{\"@type\": \"OpenUri\",\"name\": \"Abrir Build\",\"targets\": [{ \"os\": \"default\", \"uri\": \"${BUILD_URL}\" }]}]}'")
      }
      success {
        office365ConnectorSend webhookUrl: "$WEB_HOOK_URL",
                factDefinitions: [[name: "message", template: "Sucess: Deploy em $DEPLOY_STAGE de $REPO"],
                                  [name: "status", template: "Sucesso"]],
                color: "#00FF00",
                status: "Success"

        sh("curl -v --location --request POST '$WEB_HOOK_URL' --header 'Content-Type: application/json' --data-raw '{\"@type\": \"MessageCard\",\"@context\": \"http://schema.org/extensions\",\"themeColor\": \"#00FF00\",\"summary\": \"Teste de Mensagens EndPoint Jenkins\",\"sections\": [{\"activityTitle\": \"Jenkins avisa!\",\"activitySubtitle\": \"Resultado do build\",\"activityImage\": \"https://ac-buckets-dev-acpublicmedia-2cxkd4j0deg1.s3.amazonaws.com/icons/GreenThumbUP.png\",\"facts\": [{\"name\": \"Message\",\"value\": \"Sucesso: Deploy em $DEPLOY_STAGE de $REPO\"}, {\"name\": \"Status\",\"value\": \"Success\"},{\"name\": \"Job\",\"value\": \"${JOB_NAME}:${BUILD_NUMBER}\"}],\"markdown\": true}],\"potentialAction\": [{\"@type\": \"OpenUri\",\"name\": \"Abrir Build\",\"targets\": [{ \"os\": \"default\", \"uri\": \"${BUILD_URL}\" }]}]}'")
      }
    }

Logs:

[Office365connector] Failed to post data to webhook - webhook
    javax.net.ssl.SSLException: hostname in certificate didn't match: <> != </*.clo.footprintdns.com/*.hotmail.com/*.internal.outlook.com/*.live.com/*.nrb.footprintdns.com/*.office.com/*.office365.com/*.outlook.com/*.outlook.office365.com/attachment.outlook.live.net/attachment.outlook.office.net/attachment.outlook.officeppe.net/attachments.office.net/attachments-sdf.office.net/ccs.login.microsoftonline.com/ccs-sdf.login.microsoftonline.com/hotmail.com/mail.services.live.com/office365.com/outlook.com/outlook.office.com/substrate.office.com/substrate-sdf.office.com/outlook.com>
        at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.verifyHostName(SSLProtocolSocketFactory.java:339)
        at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.verifyHostName(SSLProtocolSocketFactory.java:275)
        at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.verifyHostName(SSLProtocolSocketFactory.java:258)
        at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket(SSLProtocolSocketFactory.java:167)
        at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:714)
        at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:394)
        at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:178)
        at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:404)
        at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:330)
        at jenkins.plugins.office365connector.HttpWorker.run(HttpWorker.java:83)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)

How can i solve this problem ?


Solution

  • the webhook server https://compasso.webhook.office.com/ was changed to https://outlook.office.com/webhook and it worked