如何从 azure devops 上的图表 yaml 文件中获取 appVersion?

Posted

技术标签:

【中文标题】如何从 azure devops 上的图表 yaml 文件中获取 appVersion?【英文标题】:How to get appVersion from chart yaml file on azure devops? 【发布时间】:2021-12-30 08:02:33 【问题描述】:

我想从 chart.yaml 文件中获取 appVersion 并与从 project.csproj 文件中获取的版本进行比较。

所以,我创建了三个任务

    从 project.csproj 获取版本的版本阅读器 文件内容到变量以从chart.yaml获取内容 比较版本和appVersion的powerscript shell

文件内容到变量获取所有内容。我只想获取appversion。

怎么可能像这样$env:helmchart_appVersion 如何从 chart.yaml 获取 appVersion ?

这是我的例子。

$env:Project_Version 正在从版本阅读器获取

$env:helmchart 正在从文件内容获取变量

chart.yaml 文件:

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"

比较脚本:

 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!'

【问题讨论】:

什么不适用于您的解决方案?你采取了哪些步骤来调试它? 文件内容到变量获取所有内容。我只想获取 appversion。 【参考方案1】:

我注意到了,缺少的双引号没有给出错误。

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

所以脚本应该是:

 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!'

【讨论】:

以上是关于如何从 azure devops 上的图表 yaml 文件中获取 appVersion?的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Azure Devops 中添加我们自己的自定义图表

如何将软件构建从 Azure DevOps 部署到内部服务器?

如何从 Azure Devops 服务器迁移到 Azure Devops 服务中的现有组织

如何将 TFVC 项目从 Azure DevOps 服务器迁移到新的 Azure DevOps 帐户作为 Git 存储库

如何在 Azure devops 中设置构建管道 [关闭]

如何从 Azure DevOps Pipeline 读取 Azure 文件共享文件