问题描述
通过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 )
根据以上信息,就尝试使用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。
因为这里只有两种选项( Tomcat 和Java SE )。于是,修改为Java SE后,再次部署jar包。
成功。
当问题解决后,想进一步验证是否是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的状态码
附录一:使用 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