I have a pom.xml
file that includes my project version like this
<version> 1.14.0 </version>
and I also have a YAML file that autogenerates a GitHub tag when the tests have passed and it's like this
- job: createTag
dependsOn: ifBranchIsMaster
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')
steps:
- task: GitHubRelease@0
displayName: ‘Create GitHub Release’
inputs:
gitHubConnection: $(GITHUB_CONNECTION)
repositoryName: $(GITHUB_REPO)
action: create
tag: 1.14.0
and I want to remove from my YAML file the hard-coded version tag and read it from pom.xml
immediately is there any way that can happen I try to minimize the hard-coded version to 1. I want to change it in 1 place and change everywhere.
so I figured out a script that solves my problem and reads the <version>1.14.1</version>
inside all the pom.xml
thats a powershell script
[xml]$pomXml = Get-Content .\pom.xml
# version
Write-Host $pomXml.project.version
$version=$pomXml.project.version
Write-Host "##vso[task.setvariable variable=version]$version"
and also i will provide and bash script in case of anyone want it
#!/usr/bin/env bash
version=$(grep version pom.xml | grep -v '<?xml' | grep '<version>'|head -n 1|awk '{print $1}'| cut -d'>' -f 2 | cut -d'<' -f 1)
echo "##vso[task.setvariable variable=version]$version"
that's the ways I find that I can get the version from the pom.xml