简体   繁体   中英

How to get appVersion from chart yaml file on azure devops?

I want to get appVersion from chart.yaml file and compare with version which getting from project.csproj file.

So, I create three tasks that

  1. version reader which getting version from project.csproj
  2. file content to variable to get content from chart.yaml
  3. powerscript shell that compare version and appVersion

file content to variable get all content. I only want to get appversion.

How to possible like this $env:helmchart_appVersion How can I get appVersion from chart.yaml?

here my example.

$env:Project_Version is getting from Version Reader

$env:helmchart is getting from File content to variable

chart.yaml file:

apiVersion: v2
name: asset-api
description: Helm Chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.5.2

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.0.2"

compare script:

 write-host($env:helmchart)
 write-host($env:helmchart -match "appVersion: ")
 write-host($env:Project_Version)
if($env:helmchart -match "appVersion: " + $env:Project_Version) {
     write-host('Helm Chart appVersion Validated!')
}
else {
 write-error 'Helm Chart appVersion not matched with your project version! Check Chart.yaml file!'
}

I noticed that, the missing double quote failed to give error.

$env:Project_Version is 1.0.2
$env:helmchart is appVersion: "1.0.2"

So the script should be:

 if($env:helmchart -match 'appVersion: "' + $env:Project_Version '"') 
{
     write-host('Helm Chart appVersion Validated!')
}
else 
{
   write-error 'Helm Chart appVersion not matched with your project version! Check 
    Chart.yaml file!'
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM