I have a .Net project includes Chart.yaml
I want to set a version in the file when running pipeline.
Powershell
$newversion = "v5.0.0-a"
$chartyaml = "Chart.yaml"
$yamlText = (Get-Content $chartyaml)
$yamlText.replace('appVersion: .*','appVersion: $newversion')
$yamlText > $chartyaml
Chart.yaml
apiVersion: v2
appVersion: "v5.0.0-a"
description: A Helm chart for Kubernetes
name: application-api
version: "v5.0.0-a"
type: application
CodePudding user response:
A work around for your scenario is using PythonScript as below:
def change_yaml_content(file_path, key, value):
with open(file_path, 'r') as f:
data = yaml.load(f, Loader=yaml.FullLoader)
data[key] = value
with open(file_path, 'w') as f:
yaml.dump(data, f)
file_path = "YAML_Folder/Chart.yml"
key = "appVersion"
value = "1.0.0"
change_yaml_content(file_path, key, value)
This script is for helping specify your appVersion, if you would like to specify another section, you can just change "appVersion" to specify another section.
CodePudding user response:
See a sample here - https://github.com/relizaio/rebom/blob/master/.github/workflows/github_actions.yml - line 283 and below.
Note, that the script is for GitHub Actions but you could use same idea for Azure DevOps.