我想從 chart.yaml 檔案中獲取 appVersion 并與從 project.csproj 檔案中獲取的版本進行比較。
所以,我創建了三個任務
- 從 project.csproj 獲取版本的版本閱讀器
- 檔案內容到變數以從 chart.yaml 獲取內容
- 比較版本和 appVersion 的 powerscript shell
檔案內容到變數獲取所有內容。我只想得到appversion。
如何可能像這樣$env:helmchart_appVersion
我如何從 chart.yaml 獲取 appVersion ?
這是我的例子。
$env:Project_Version是從 Version Reader 獲取的
$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!'
}
uj5u.com熱心網友回復:
我注意到,缺少的雙引號未能給出錯誤。
$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!'
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/363112.html
標籤:正则表达式 电源外壳 azure-devops 管道
