問題描述

通過github aciton部署azure app service服務的時候,遇見400報錯。

報錯信息非常簡單:

Starting deployment for web app...
Package deployment using OneDeploy initiated.
Error: Failed to deploy web package to App Service.
Error: Deployment Failed, Error: Failed to deploy web package using OneDeploy to App Service.
Bad Request (CODE: 400)

這個問題應該如何調查呢?

 

問題解答

在Github Aciton中,使用 Azure WebApp(azure/webapps-deploy@v3)來部署App Service的應用, 這次部署的是一個jar包。

Github Action 腳本:

- name: Azure WebApp
uses: azure/webapps-deploy@v3
with:
app-name: '<app service name>'
package: ${{ github.workspace }}/target/*.jar

查看Azure文檔,介紹部署java應用時,使用az cli命令,github action和maven 插件都是使用的Kudu OneDeploy接口( https://<your web app>.scm.chinacloudsites.cn/api/publish?type=jar )

【Azure Web App】Github Action部署Jar包到App Service報400錯誤 _jar

(文檔鏈接:https://docs.azure.cn/zh-cn/app-service/configure-language-java-deploy-run?tabs=linux&pivots=java-tomcat#deploying-your-app)

 

根據以上信息,就嘗試使用az webapp deploy命令直接部署jar包應用,發現多了一句錯誤提示信息:

az webapp deploy --resource-group <your resource group name> --name <your app service name> --src-path myjava.jar --type jar

Initiating deployment
Deploying from local path: myjava.jar
An error occurred during deployment. Status Code: 400,

Details: "Artifact type = 'Jar' cannot be deployed to stack = 'TOMCAT'. Site should be configured to run with stack = JAVA",

Please visit https://XXXXXXXXX.scm.chinacloudsites.cn/api/deployments/latest to get more information about your deployment

這句錯誤消息非常關鍵(Artifact type = 'Jar' cannot be deployed to stack = 'TOMCAT'. Site should be configured to run with stack = JAVA")。

在查看App Service的配置信息後,Stack果然設置為Tomcat。

【Azure Web App】Github Action部署Jar包到App Service報400錯誤 _java_02

因為這裏只有兩種選項( Tomcat 和Java SE )。於是,修改為Java SE後,再次部署jar包。

【Azure Web App】Github Action部署Jar包到App Service報400錯誤 _jar_03

成功。

 

當問題解決後,想進一步驗證是否是one deploy接口對jar包的強制限制。

恰好kudu也是開源項目,所以,進入github kudu 倉庫 (源碼:https://github.com/projectkudu/kudu/tree/master ),使用錯誤消息關鍵字整庫搜索“cannot be deployed to stack”,最終,定位到 PushDeploymentController.cs 中,有如下的驗證條件:

  • 當部署的文件為Jar時,需要判斷目標App Service的Stack只能是JavaSE。如果不是,返回400的狀態碼

【Azure Web App】Github Action部署Jar包到App Service報400錯誤 _jar_04

 

附錄一:使用 curl 命令直接調用接口也可以復現問題,效果和az webapp deploy命令相同

curl -X POST \

     -u user:password \

     -T "/Users/Downloads/xxxxx-0.0.1-SNAPSHOT.jar" \

     "https://xxxxx.scm.chinacloudsites.cn/api/publish?type=jar" \

     -v



* Host xxxxx.scm.chinacloudsites.cn:443 was resolved.

* IPv6: (none)

* IPv4: 159.27.20.0

*   Trying 159.27.20.0:443...

* Connected to xxxxx.scm.chinacloudsites.cn (159.27.20.0) port 443

* ALPN: curl offers h2,http/1.1

* (304) (OUT), TLS handshake, Client hello (1):

*  CAfile: /etc/ssl/cert.pem

*  CApath: none

* (304) (IN), TLS handshake, Server hello (2):

* (304) (OUT), TLS handshake, Client hello (1):

* (304) (IN), TLS handshake, Server hello (2):

* (304) (IN), TLS handshake, Unknown (8):

* (304) (IN), TLS handshake, Certificate (11):

* (304) (IN), TLS handshake, CERT verify (15):

* (304) (IN), TLS handshake, Finished (20):

* (304) (OUT), TLS handshake, Finished (20):

* SSL connection using TLSv1.3 / AEAD-AES256-GCM-SHA384 / [blank] / UNDEF

* ALPN: server accepted http/1.1

* Server certificate:

*  subject: C=CN; ST=Shanghai; O=Shanghai Blue Cloud Technology Co., Ltd.; CN=*.chinacloudsites.cn

*  start date: Dec 19 00:00:00 2025 GMT

*  expire date: Jun 17 23:59:59 2026 GMT

*  subjectAltName: host "xxxxx.scm.chinacloudsites.cn" matched cert's "*.scm.chinacloudsites.cn"

*  issuer: C=US; O=DigiCert Inc; CN=DigiCert Basic RSA CN CA G2

*  SSL certificate verify ok.

* using HTTP/1.x

* Server auth using Basic with user 'deploypoc'

> POST /api/publish?type=jar HTTP/1.1

> Host: xxxxx.scm.chinacloudsites.cn

> Authorization: Basic xxxxxxxxxxxxxxxx

> User-Agent: curl/8.7.1

> Accept: */*

> Content-Length: 25578166

> Expect: 100-continue

> 

* Done waiting for 100-continue

< HTTP/1.1 400 Bad Request

< Content-Type: text/plain; charset=utf-8

< Date: Wed, 31 Dec 2025 03:42:36 GMT

< Server: Kestrel

< Set-Cookie: ARRAffinity=xxxx;Path=/;HttpOnly;Secure;Domain=xxxxx.scm.chinacloudsites.cn

< Set-Cookie: ARRAffinitySameSite=xxxxx;Path=/;HttpOnly;SameSite=None;Secure;Domain=xxxxx.scm.chinacloudsites.cn

< Transfer-Encoding: chunked

< 

* HTTP error before end of send, stop sending

* abort upload after having sent 589824 bytes

* Closing connection

Artifact type = 'Jar' cannot be deployed to stack = 'TOMCAT'. Site should be configured to run with stack = JAVA%

 

 

參考資料

App Service部署Java應用:https://docs.azure.cn/zh-cn/app-service/configure-language-java-deploy-run?tabs=linux&pivots=java-tomcat#deploying-your-app

Kudu One Deploy Source Code : https://github.com/projectkudu/kudu/blob/master/Kudu.Services/Deployment/PushDeploymentController.cs#L304

 



當在複雜的環境中面臨問題,格物之道需:濁而靜之徐清,安以動之徐生。 雲中,恰是如此!