Home > Enterprise >  Azure Pipeline - Publish Maven Artifacts Without Comitting to Repository
Azure Pipeline - Publish Maven Artifacts Without Comitting to Repository

Time:03-16

New to Azure in general so sorry if my question isn't as concise as it should be.

What I'm trying to do: When someone pushes to master I want the pipeline to bump the project version and release it as an artifact that is available in the Artifacts tab. This shouldn't create any additional commits.

What I've tried: To verify that my local connection to Artifacts was working I tried mvn deploy which worked fine but it doesn't handle version bumping automatically, so instead I tried switching over to

mvn -B release:prepare release:perform

As it does take care of bumping but this creates other issues as it commits two additional times to git instead of amending itself onto the head and I need to tinker with soft resets and force push to get it correct. Also not sure if it does release to Artifacts as I had issues getting git credentials working...

Is there a way for the pipeline to look at what Artifacts has already been released and just bump based on that so it doesn't have to commit anything to the repository?

CodePudding user response:

The Azure Artifacts which's on the left-hand menu is designed to be consumed as shared modules, which is for custom packages instead of publish build artifacts. For the Build artifacts, you might check specific pipeline(which finished run) → "Summary" → "Related", and you can see what pipeline published.

I don't know if I misunderstand your question, and this link might help you get some idea.

CodePudding user response:

Okay, so after a lot of days I finally got it workig. Releasing artifacts without committing code to repo using organization feeds

# Maven
# Build your Java project and run tests with Apache Maven.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/java

trigger:
  - main

pool:
  vmImage: ubuntu-latest

variables:
  - name: artifactVersion
  - name: packageName
    value: 'group.name:artifact.name'

steps:
  - task: PowerShell@2
    inputs:
      targetType: 'inline'
      script: |
        
        # Get list over packages
        $url = 'https://feeds.dev.azure.com/<organization>/_apis/packaging/Feeds/<feedName>/packages?api-version=6.0-preview.1'
        $pipeline = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}

        # Find artifact in the list
        $packageId = ''
        Foreach ($package IN $pipeline.value) {
          if($package.name -eq '$(packageName)') {
            $packageId = $package.id
          }
        }
        $url = 'https://feeds.dev.azure.com/<organization>/_apis/packaging/Feeds/<feedName>/Packages/'   $packageId   '/versions?api-version=6.0-preview.1'
        $pipeline = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}

        $artifactVersion = [int]$pipeline.value[0].version 1
        Write-Host "##vso[task.setvariable variable=artifactVersion]$artifactVersion"
        echo "Preparing release for artifaction version: $artifactVersion"
    env:
      SYSTEM_ACCESSTOKEN: $(System.AccessToken)
    displayName: Fetching latest version of artifact
  - task: MavenAuthenticate@0
    inputs:
      artifactsFeeds: <feedName>
  - task: PowerShell@2
    inputs:
      targetType: 'inline'
      script: |

        echo "Artifact version to be released: $(artifactVersion)"
        $userNameOfHead = git log -1 --pretty=format:'%an'
        $userEmailOfHead = git log -1 --pretty=format:'           
  • Related