humble
humble

Reputation: 97

How to build a jar file on Azure and copy to Artifactory?

I have an Azure pipeline that is supposed to be building my java code with maven. The YAML looks like this:

steps:
- task: Maven@3
  inputs:
    mavenPomFile: '$(system.defaultWorkingDirectory)/<project-name>/pom.xml'
    mavenOptions: '-Xmx3072m'
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '1.8'
    jdkArchitectureOption: 'x64'
    publishJUnitResults: false
    testResultsFiles: '**/TEST-*.xml'
    goals: 'package'
     #allowBrokenSymlinks: 
    
# Copy jar file from a source folder to a target folder
- task: CopyFiles@1
  inputs:
    sourceFolder: '$(system.defaultWorkingDirectory)/<project-name>/target'
    contents: 'filename.jar' 
    targetFolder: '$(Build.ArtifactStagingDirectory)'
    cleanTargetFolder: false # Optional
    overWrite: true # Optional

I was expecting there to be a jar file in the /target but nothing shows up there. Then, since there is no jar file created, the copy to Artifactory doesn't work either. The pipeline runs without error. Azure docs are clear as mud.

I'm new to Azure and Artifactory so please keep it simple if you can help!

Upvotes: 1

Views: 2697

Answers (2)

el07
el07

Reputation: 65

Have you tried using Wild Card for fetching the jar?

Example:

 - task: CopyFiles@1
   inputs:
     sourceFolder: '$(system.defaultWorkingDirectory)/<project-name>/target'
     contents: *.jar
     targetFolder: '$(Build.ArtifactStagingDirectory)'
     cleanTargetFolder: false # Optional
     overWrite: true # Optional

Upvotes: 0

yahavi
yahavi

Reputation: 6033

The easiest and most recommended way is to use the Artifactory Azure DevOps extension. The extension uses the JFrog CLI to build and upload your Maven JARs to Artifactory.

After downloading and installation of the extension, you can configure your pipeline in 2 steps

  1. Configure Artifactory service connection.
  2. In your pipeline, configure Artifactory Maven build. To Make it upload the JARs to Artifactory, please run the Maven install goal instead of package.

For more information see:

  1. Extension documentation
  2. Webinar
  3. General information about the JFrog CLI.

Upvotes: 1

Related Questions