Wim Deblauwe
Wim Deblauwe

Reputation: 26858

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

I have a Spring Boot application running as an Azure App Service. I can deploy it using the Maven plugin, but not from Jenkins. The strange thing is that it has already worked from Jenkins before.

When deploying with Maven (using mvn azure-webapp:deploy), I see something like:

[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):

                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

Upvotes: 1

Views: 504

Answers (1)

Wim Deblauwe
Wim Deblauwe

Reputation: 26858

The problem is that the Azure Jenkins plugin checks the linuxFxVersion to contain jre. But if you use Java 11, this is not the case (The value is something like JAVA|11-java11). Because of that, it wrongly thinks that it is not a Java platform to deploy to.

I fixed the issue and opened a PR at https://github.com/jenkinsci/azure-app-service-plugin/pull/63.

I am currently using my locally build version until they pick up this PR.

Next to that, I also had to create a zip file to make it fully work:

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"
}       

Upvotes: 1

Related Questions