找回密码
 立即注册
首页 业界区 业界 【Azure Web App】Github Action部署Jar包到App Service ...

【Azure Web App】Github Action部署Jar包到App Service报400错误

客臂渐 6 天前
问题描述

通过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: ''
package: ${{ github.workspace }}/target/*.jar

查看Azure文档,介绍部署java应用时,使用az cli命令,github action和maven 插件都是使用的Kudu OneDeploy接口( https://.scm.chinacloudsites.cn/api/publish?type=jar )
1.png

(文档链接: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  --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。
2.png

因为这里只有两种选项( Tomcat 和Java SE )。于是,修改为Java SE后,再次部署jar包。
3.png

成功。
 
当问题解决后,想进一步验证是否是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的状态码
4.png

 
附录一:使用 curl 命令直接调用接口也可以复现问题,效果和az webapp deploy命令相同
  1. curl -X POST \
  2.      -u user:password \
  3.      -T "/Users/Downloads/xxxxx-0.0.1-SNAPSHOT.jar" \
  4.      "https://xxxxx.scm.chinacloudsites.cn/api/publish?type=jar" \
  5.      -v
  6. * Host xxxxx.scm.chinacloudsites.cn:443 was resolved.
  7. * IPv6: (none)
  8. * IPv4: 159.27.20.0
  9. *   Trying 159.27.20.0:443...
  10. * Connected to xxxxx.scm.chinacloudsites.cn (159.27.20.0) port 443
  11. * ALPN: curl offers h2,http/1.1
  12. * (304) (OUT), TLS handshake, Client hello (1):
  13. *  CAfile: /etc/ssl/cert.pem
  14. *  CApath: none
  15. * (304) (IN), TLS handshake, Server hello (2):
  16. * (304) (OUT), TLS handshake, Client hello (1):
  17. * (304) (IN), TLS handshake, Server hello (2):
  18. * (304) (IN), TLS handshake, Unknown (8):
  19. * (304) (IN), TLS handshake, Certificate (11):
  20. * (304) (IN), TLS handshake, CERT verify (15):
  21. * (304) (IN), TLS handshake, Finished (20):
  22. * (304) (OUT), TLS handshake, Finished (20):
  23. * SSL connection using TLSv1.3 / AEAD-AES256-GCM-SHA384 / [blank] / UNDEF
  24. * ALPN: server accepted http/1.1
  25. * Server certificate:
  26. *  subject: C=CN; ST=Shanghai; O=Shanghai Blue Cloud Technology Co., Ltd.; CN=*.chinacloudsites.cn
  27. *  start date: Dec 19 00:00:00 2025 GMT
  28. *  expire date: Jun 17 23:59:59 2026 GMT
  29. *  subjectAltName: host "xxxxx.scm.chinacloudsites.cn" matched cert's "*.scm.chinacloudsites.cn"
  30. *  issuer: C=US; O=DigiCert Inc; CN=DigiCert Basic RSA CN CA G2
  31. *  SSL certificate verify ok.
  32. * using HTTP/1.x
  33. * Server auth using Basic with user 'deploypoc'
  34. > POST /api/publish?type=jar HTTP/1.1
  35. > Host: xxxxx.scm.chinacloudsites.cn
  36. > Authorization: Basic xxxxxxxxxxxxxxxx
  37. > User-Agent: curl/8.7.1
  38. > Accept: */*
  39. > Content-Length: 25578166
  40. > Expect: 100-continue
  41. >
  42. * Done waiting for 100-continue
  43. < HTTP/1.1 400 Bad Request
  44. < Content-Type: text/plain; charset=utf-8
  45. < Date: Wed, 31 Dec 2025 03:42:36 GMT
  46. < Server: Kestrel
  47. < Set-Cookie: ARRAffinity=xxxx;Path=/;HttpOnly;Secure;Domain=xxxxx.scm.chinacloudsites.cn
  48. < Set-Cookie: ARRAffinitySameSite=xxxxx;Path=/;HttpOnly;SameSite=None;Secure;Domain=xxxxx.scm.chinacloudsites.cn
  49. < Transfer-Encoding: chunked
  50. <
  51. * HTTP error before end of send, stop sending
  52. * abort upload after having sent 589824 bytes
  53. * Closing connection
  54. 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
 

来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

相关推荐

您需要登录后才可以回帖 登录 | 立即注册