Home > Software design >  Reading YAML config file and creating environment variables
Reading YAML config file and creating environment variables

Time:07-29

I was wondering what is the best approach to reading in the yaml config and setting environment variables.

For example, my yaml config looks like this:

amps-ml:
  models:
    - name: app-sample
      type: sagemaker
      inference:
        image: project_id.dkr.ecr.us-west-2.amazonaws.com/template-model-bert:test_1
        data: s3://my_project/sagemaker/huggingface-pytorch-inference-recommender/sentiment-analysis/model/model.tar.gz
        endpoint: amp-app-endpoint-test
        model_name: sample-model
        endpoint_config_name: amp-app-config
        model_package_group_name: sample-package-group
        endpoint_instance_count: 1,
        endpoint_instance_type: ml.m5.large

I essentially want to set environment variables in my Jenkins pipeline for all the variables under inference.

CodePudding user response:

Try

def yaml = readYAML file: "your-file.yaml"
yaml["amps-ml"]["models"][0]["inference"].each {name, value ->
env["$name"] = value
} 

You can also iterate the models instead of using explicit index (0)

  • Related