Siddharth Seth
Siddharth Seth

Reputation: 664

Split Jenkins CASC yaml content across multiple files

I am using Jenkins CasC plugin to manage configuration for Jenkins. As part of the effort, I have a set of files with the required config in YAML format. I want to split the configuration for the ec2 plugin by having a file for each AMI template. The file structure looks like below:

jenkins:
  clouds:
    - amazonEC2:
      name: "xxxxxx"
      instanceCapStr: "50"
      region: "region"
      sshKeysCredentialsId: "credentialsId"
      templates:
      - ami: "ami1-name"
        
      - ami: "ami2-name"

      useInstanceProfileForCredentials: false

I want to convert this into a structure that looks like below:

jenkins:
  clouds:
    - amazonEC2:
      name: "xxxxxx"
      instanceCapStr: "50"
      region: "region"
      sshKeysCredentialsId: "credentialsId"
      templates:
      - ${file(path to config of ami1)}
        
      - ${file(path to config of ami2)}

      useInstanceProfileForCredentials: false

ami1 config

- ami: "ami1-name"
  ...

ami2 config

- ami: "ami2-name"
  ...

I am copying these files into the CASC Jenkins folder and expect them to be merged using SnakeYaml parser by the CASC plugin. But instead receive an error on Jenkins startup related to an unexpected configuration element that looks like the below:

SEVERE  jenkins.InitReactorRunner$1#onTaskFailed: Failed ConfigurationAsCode.init
java.lang.IllegalArgumentException: Single entry map expected to configure a hudson.slaves.Cloud

Upvotes: 0

Views: 581

Answers (1)

Andy
Andy

Reputation: 965

Your yaml formatting is the problem. The cloud yaml config needs to be structured like:

jenkins:
  clouds:
    - amazonEC2:
        name: "xxxxxx"
        ...

As per the error message "Single entry map expected", where amazonEC2 is the single entry map with its configuration below it.

Upvotes: 0

Related Questions