Azure DevOps Maven Build PIpeline - 将构建 ID 添加到清单文件
Azure DevOps Maven Build PIpeline - Add build id to the Manifest File
有没有办法将构建 ID 添加到 EAR 的清单文件中?
我已经尝试添加变量,并且我“认为”我已经添加了 Maven 选项,我通常会在命令行上放置这些选项以在我的 POM 中设置变量。但是似乎没有任何效果。
# 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
- 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'
Build.BuildId 是一个预定义变量,它是已完成构建的记录 ID。同样,Build.BuildNumber 是已完成构建的名称,也称为 运行 编号。您可以在此值中指定 what is included。此变量的典型用途是使其成为您在存储库选项卡上指定的标签格式的一部分。
我检查了几个 Microsoft 文档和博客,但没有找到任何将构建 ID 添加到 EAR 的清单文件的具体方法。我发现的唯一方法是仅添加变量。 如果您使用的是 YAML 或经典构建管道,请参阅predefined variables 以获得完整的系统变量列表。
阅读本文Understand variable syntax了解引用变量的三种不同方式。
有没有办法将构建 ID 添加到 EAR 的清单文件中? 我已经尝试添加变量,并且我“认为”我已经添加了 Maven 选项,我通常会在命令行上放置这些选项以在我的 POM 中设置变量。但是似乎没有任何效果。
# 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
- 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'
Build.BuildId 是一个预定义变量,它是已完成构建的记录 ID。同样,Build.BuildNumber 是已完成构建的名称,也称为 运行 编号。您可以在此值中指定 what is included。此变量的典型用途是使其成为您在存储库选项卡上指定的标签格式的一部分。
我检查了几个 Microsoft 文档和博客,但没有找到任何将构建 ID 添加到 EAR 的清单文件的具体方法。我发现的唯一方法是仅添加变量。 如果您使用的是 YAML 或经典构建管道,请参阅predefined variables 以获得完整的系统变量列表。
阅读本文Understand variable syntax了解引用变量的三种不同方式。