如何決議 yaml 檔案以從中提取 appVersion?
我可以將檔案內容與檔案內容一起讀取到變數以獲取所有內容,但我無法決議 yaml 檔案以從中提取 appVersion。
PowerShell 腳本:
# get chart.yaml file content to yamlfilecontent variable.
write-host($env:yamlfilecontent)
# how to parse content ?
write-host($env:yamlfilecontent["appVersion"])
圖表.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"
uj5u.com熱心網友回復:
不幸的是,從 7.2 版本開始,PowerShell沒有決議 YAML 的內置支持 - 請參閱GitHub 問題 #3607 中的相關功能請求。
但是,可以使用第三方模塊,例如powershell-yaml,可從此處的 PowerShell 庫中獲得,您可以從此處將其直接部署到 Azure 自動化。要在本地安裝它,請使用Install-Module -Name powershell-yaml.
假設模塊已安裝,以下是如何決議問題中的 YAML,使用here-string定義輸入文本:
$yamlText = @'
apiVersion: v2
name: asset-api
description: Helm Chart for Kubernetes
# A chart can be either an 'application' or a 'library' chart.
# ...
version: 1.5.2
# This is the version number of the application being deployed. This version number should be
# ...
appVersion: "1.0.2"
'@
($yamlText | ConvertFrom-Yaml).appVersion
1.0.2如預期的那樣,上述產量為 。
ConvertFrom-Yaml輸出一個表示 YAML 輸入的有序哈希表(技術上,一個 type 的實體[System.Collections.Specialized.OrderedDictionary]),其條目 PowerShell 允許您訪問,就好像它們是屬性(例如.appVersion)或使用索引語法(例如['appVersion'])。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/362427.html
標籤:电源外壳 azure-devops 雅姆 天蓝色管道 管道
