Skip to content
Advertisement

Azure DevOps Maven Build PIpeline – Add build id to the Manifest File

Is there a way to add the build id to the Manifest file of an EAR? I have tried adding variables, and I “think” I have added the Maven Options that I would normally put on the command line to set variables in my POM. BUt nothing seems to work.

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

trigger:
- main
- dev
- qa

pool:
  vmImage: ubuntu-latest

variables:
  IsMasterBranch: $[ eq(variables['Build.SourceBranch'], 'refs/heads/main') ]
  IsDevBranch: $[ eq(variables['Build.SourceBranch'], 'refs/heads/dev') ]
  IsQABranch: $[ eq(variables['Build.SourceBranch'], 'refs/heads/qa') ]
  BUILD_NUMBER: $(Build.BuildNumber)

steps:
- powershell: >
    if('$(IsMasterBranch)' -eq 'True') {
      Write-Host "##vso[task.setvariable variable=BuildTag;isOutput=true]$(Build.BuildId)-prod"
      Write-Host "##vso[task.setvariable variable=branch;isOutput=true]prod"
      Write-Host "##vso[task.setvariable variable=FullBuildTag;isOutput=true]$(Build.Repository.Name):$(Build.BuildId)-prod"      
    }
     elseif('$(IsDevBranch)' -eq 'True') {
      Write-Host "##vso[task.setvariable variable=BuildTag;isOutput=true]$(Build.BuildId)-dev"
      Write-Host "##vso[task.setvariable variable=branch;isOutput=true]dev"
      Write-Host "##vso[task.setvariable variable=FullBuildTag;isOutput=true]$(Build.Repository.Name):$(Build.BuildId)-dev"
    }
    elseif('$(IsQABranch)' -eq 'True') {
      Write-Host "##vso[task.setvariable variable=BuildTag;isOutput=true]$(Build.BuildId)-qa"
      Write-Host "##vso[task.setvariable variable=branch;isOutput=true]qa"
      Write-Host "##vso[task.setvariable variable=FullBuildTag;isOutput=true]$(Build.Repository.Name):$(Build.BuildId)-qa"
    }




- task: Maven@3
  inputs:
    mavenPomFile: 'pom.xml'
    mavenOptions: '-Xmx3072m'
    options: '-Ddevelopment_environment=$(branch) -Dbuildnumber=434'
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '1.8'
    jdkArchitectureOption: 'x64'
    publishJUnitResults: true
    testResultsFiles: '**/surefire-reports/TEST-*.xml'
    goals: 'package'

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.SourcesDirectory)/test-hello-world-app-ear/target'
    ArtifactName: 'target'
    publishLocation: 'Container'

Advertisement

Answer

The Build.BuildId is a predefined variable and it’s the ID of the record for the completed build. And similarly Build.BuildNumber is the name of the completed build, also known as the run number. You can specify what is included in this value. A typical use of this variable is to make it part of the label format, which you specify on the repository tab.

I checked several Microsoft document and blogs but didn’t found any specific way to add the build id to the Manifest file of an EAR. The only way I found is by adding the variables only. If you are using YAML or classic build pipelines, see predefined variables for a comprehensive list of system variables.

Read this Understand variable syntax to know the three different ways to reference variables.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement