3
votes

I want to deploy my Spring Boot (Java) app on Azure using Azure DevOps. However, I cant seem to get the release pipeline working.

I already created an Azure build pipeline with the following azure-pipelines.yml:

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: Maven@3
  inputs:
    mavenPomFile: 'pom.xml'
    goals: 'package'
    options: '-Dmaven.test.skip=true'
    mavenOptions: '-Dmaven.test.skip=true'
    publishJUnitResults: false
    javaHomeOption: 'JDKVersion'
    mavenVersionOption: 'Default'
    mavenAuthenticateFeed: false
    effectivePomSkip: false
    sonarQubeRunAnalysis: false

The build is successful, so the next step is to create a Release pipeline. I selected the option 'Deploy a Java app to Azure App Service'. When I try to add the artifact, then I see the following: Screenshot of Azure release pipeline

As you can see, I get the message 'No version is available for or the latest version has no artifacts to publish. Please check the source pipeline.'. This tells me that the build pipeline did not create the artifact or that some other setting is configure incorrectly. My initial thought is that I need to add a step to azure-pipelines.yml that actually puts the artifact somewhere.

Does anyone know what is the solution?

1

1 Answers

2
votes

This tells me that the build pipeline did not create the artifact or that some other setting is configure incorrectly. My initial thought is that I need to add a step to azure-pipelines.yml that actually puts the artifact somewhere.

Yes, your initial thought is completely correct.

When you use the release pipeline to deploy the app/file, which will get the source from the artifact. So, we need to publish the app/file to the artifact in our build pipeline. The build output is in the working directory not published to the artifact, that is the reason why you get the error, No version is available for or the latest version has no artifacts to publish.

To resolve this issue, you just need to add copy task and Publish build artifacts task after Maven task to copy the .jar file and publish it to the artifacts:

steps:
- task: Maven@3
  inputs:
    mavenPomFile: 'pom.xml'
    goals: 'package'
    ...

- task: CopyFiles@2
  displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
  inputs:
    SourceFolder: '$(system.defaultworkingdirectory)'
    Contents: '**/*.jar'
    TargetFolder: '$(build.artifactstagingdirectory)'

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: drop'
  inputs:
    PathtoPublish: '$(build.artifactstagingdirectory)'

Then, we could use the release pipeline to deploy the build artifact:

enter image description here