projectkudu / kudu

Kudu is the engine behind git/hg deployments, WebJobs, and various other features in Azure Web Sites. It can also run outside of Azure.
Apache License 2.0
3.13k stars 652 forks source link

QUESTION: Using %SCM_COMMIT_MESSAGE% in deploy.cmd - issues with linebreaks... #3506

Closed mistyn8 closed 7 months ago

mistyn8 commented 8 months ago

Thought I'd add a webhook call out to MSTeams from the deploy.cmd

:: 6. Send a notification into Teams via Webhook
echo ">>>>>>>>>> MS Team Notification >>>>>>>>>>"

call :ExecuteCmd curl -i -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data "{\"type\": \"message\", \"attachments\": [{\"contentType\": \"application/vnd.microsoft.card.adaptive\", \"content\": {\"type\": \"AdaptiveCard\", \"body\": [{\"type\": \"TextBlock\", \"size\": \"Medium\", \"weight\": \"Bolder\", \"text\": \"%ASPNETCORE_ENVIRONMENT% Environment Deployed\" }, {\"type\": \"TextBlock\", \"text\": \"%SCM_COMMIT_MESSAGE% \", \"wrap\": true } ], \"$schema\": \"http://adaptivecards.io/schemas/adaptive-card.json\", \"version\": \"1.5\" } } ] }" https://{XXX}.webhook.office.com/webhookb2/{GUID}/IncomingWebhook/{GUID}

However, because the git commit message contains a final linebreak, (indeed could have multiple lines and multiple line breaks), and %SCM_COMMIT_MESSAGE% just passes the raw data, I could find no way to remove/encode the commit message so that it doesn't cause a line break(s) and break the deploy.cmd? Ideally "message line one\nmessage line two\n"?

I reverted back to using

call git show -s "%SCM_COMMIT_ID%" --pretty="%%%%h : %%%%s" > commitmessage.txt
SET /p COMMIT_MESSAGE=<commitmessage.txt

so that linebreaks are removed from the commit message, with the added benifit of getting the abbreviated commit hash (over SCM_COMMIT_ID) and other formats as required author etc..

Maybe others would have a way to not have to fallback to git show?

jvano commented 7 months ago

Hi

If the problem persists and is related to running it on Azure App Service, please open a support incident in Azure: https://learn.microsoft.com/en-us/azure/azure-portal/supportability/how-to-create-azure-support-request

This way we can better track and assist you on this case

Thanks,

Joaquin Vano Azure App Service