Mrun
Mrun

Reputation: 23

Shell script to read latest version from artifactory

In my artifactory there is a file "maven-metadata.xml", which contains all version. I wanted to pick up latest version from this file. But the issue is I want to pickup a stable version. For example in this maven-metadata.xml file:

<metadata>
<groupId>com.platform</groupId>
<artifactId>abc1.2</artifactId>
  <versioning>
    <latest>2.6.0-425-75b5083</latest>
    <release>2.6.0-425-75b5083</release>
    <versions>
      <version>2.5.0-132-b616a37</version>
      <version>2.5.1-RC1</version>
      <version>2.5.2</version>
      <version>2.6.0-425-75b5083</version>
    </versions>
    <lastUpdated>20201011113748</lastUpdated>
 </versioning>
</metadata>

But I would like to pickup the latest stable version (without alphanumeric) i.e. 2.5.2 How to filter this data in shell script?

Also I cannot directly read <latest> tag as it may contain alphanumeric version.

Upvotes: 1

Views: 425

Answers (1)

Taylor G.
Taylor G.

Reputation: 711

Assuming versions are sorted ascendingly, you can use the following command to extract latest version without alphanumeric.

sed -n 's/.*<version>\([0-9.]*\)<\/version>.*/\1/p' maven-metadata.xml | tail -n 1

Upvotes: 1

Related Questions