简体   繁体   English

Spring Boot 应用程序的 Azure 应用服务部署在 Jenkins 中不起作用

[英]Azure App Service deploy of Spring Boot app not working from Jenkins

I have a Spring Boot application running as an Azure App Service.我有一个作为 Azure 应用服务运行的 Spring Boot 应用程序。 I can deploy it using the Maven plugin, but not from Jenkins.我可以使用 Maven 插件部署它,但不能从 Jenkins 部署。 The strange thing is that it has already worked from Jenkins before.奇怪的是,它之前已经从 Jenkins 工作过。

When deploying with Maven (using mvn azure-webapp:deploy ), I see something like:使用 Maven 部署时(使用mvn azure-webapp:deploy ),我看到如下内容:

[INFO] Auth Type : AZURE_CLI, Auth Files : [/Users/wdb/.azure/azureProfile.json, /Users/wdb/.azure/accessTokens.json]
[INFO] [Correlation ID: ab463b1c-xxxx-xxxx-xxxx-xxxxxxxxxxxx] Instance discovery was successful
[INFO] Subscription : MY_SUBSCRIPTION(797bdef0-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
[INFO] Updating App Service Plan...
[INFO] Updating target Web App...
[INFO] Successfully updated Web App.
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource to /Users/wdb/Projects/my-project/target/azure-webapp/my-project-backend-staging-80a97da7-6abf-49f4-9f4f-df92b8d38e20
[INFO] Trying to deploy artifact to my-project-backend-staging...
[INFO] Renaming /Users/wdb/Projects/my-project/target/azure-webapp/my-project-backend-staging-80a97da7-6abf-49f4-9f4f-df92b8d38e20/my-project-backend-staging-0.0.1-SNAPSHOT.jar to app.jar
[INFO] Deploying the zip package my-project-backend-staging-80a97da7-6abf-49f4-9f4f-df92b8d38e204401718728513612670.zip...
[INFO] Successfully deployed the artifact to https://my-project-backend-staging.azurewebsites.net

I have this in my Jenkinsfile (using the Azure App Service Jenkins Plugin ):我的Jenkinsfile有这个(使用Azure App Service Jenkins 插件):

                dir('target') {
                    sh '''
                        cp my-project-backend-*.jar app.jar
                        '''

                    azureWebAppPublish azureCredentialsId: 'JenkinsMyProjectBackendServicePrincipal',
                            resourceGroup: 'MYPROJECT-BACKEND',
                            appName: 'myproject-backend',
                            filePath: "app.jar"
                }

When the build is run, I see this in the logging:当构建运行时,我在日志中看到:

hudson.plugins.git.GitException: Command "git fetch --tags --force --progress -- https://myproject-backend-staging.scm.azurewebsites.net:443/myproject-backend-staging.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: remote: Counting objects: 74, done.        
remote: Compressing objects:   2% (1/48)           
remote: Compressing objects:   4% (2/48)           
remote: Compressing objects:   6% (3/48)           
remote: Compressing objects:   8% (4/48)           
remote: Compressing objects:  10% (5/48)           
remote: .

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2450)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2051)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:84)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:573)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:802)
    at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:161)
    at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:154)
    at hudson.remoting.UserRequest.perform(UserRequest.java:211)
    at hudson.remoting.UserRequest.perform(UserRequest.java:54)
    at hudson.remoting.Request$2.run(Request.java:375)
    at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:73)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE

The problem is that the Azure Jenkins plugin checks the linuxFxVersion to contain jre .问题在于 Azure Jenkins 插件会检查linuxFxVersion以包含jre But if you use Java 11, this is not the case (The value is something like JAVA|11-java11 ).但是,如果您使用 Java 11,则情况并非如此(该值类似于JAVA|11-java11 )。 Because of that, it wrongly thinks that it is not a Java platform to deploy to.因此,它错误地认为它不是要部署到的 Java 平台。

I fixed the issue and opened a PR at https://github.com/jenkinsci/azure-app-service-plugin/pull/63 .我解决了这个问题并在https://github.com/jenkinsci/azure-app-service-plugin/pull/63 上打开了一个 PR。

I am currently using my locally build version until they pick up this PR.我目前正在使用我的本地构建版本,直到他们拿起这个 PR。

Next to that, I also had to create a zip file to make it fully work:接下来,我还必须创建一个 zip 文件以使其完全正常工作:

dir('target') {
    sh '''
        cp my-project-backend-*.jar app.jar
        '''
    zip zipFile: 'app.zip', glob: 'app.jar'

    azureWebAppPublish azureCredentialsId: 'JenkinsMyProjectBackendServicePrincipal',
            resourceGroup: 'MYPROJECT-BACKEND',
            appName: 'my-project-backend-staging',
            filePath: "app.zip"
}       

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM