in templater/jobs/utils/utils.go [39:92]
func UnmarshalJobs(jobDir string) (map[string]types.JobConfig, error) {
jobList := map[string]types.JobConfig{}
files, err := ioutil.ReadDir(jobDir)
if err != nil {
return nil, fmt.Errorf("error reading job directory %s: %v", jobDir, err)
}
for _, file := range files {
fileName := file.Name()
filePath := filepath.Join(jobDir, fileName)
if strings.Contains(fileName, "1-X") {
for _, releaseBranch := range releaseBranches {
var jobConfig types.JobConfig
releaseBranchBasedFileName := strings.ReplaceAll(fileName, "1-X", releaseBranch)
data := map[string]interface{}{
"releaseBranch": releaseBranch,
}
contents, err := ioutil.ReadFile(filePath)
if err != nil {
return nil, fmt.Errorf("error reading job YAML %s: %v", filePath, err)
}
templatedContents, err := ExecuteTemplate(string(contents), data)
if err != nil {
return nil, fmt.Errorf("error executing template: %v", err)
}
err = yaml.Unmarshal(templatedContents, &jobConfig)
if err != nil {
return nil, fmt.Errorf("error unmarshaling contents of file %s: %v", filePath, err)
}
jobList[releaseBranchBasedFileName] = jobConfig
}
} else {
var jobConfig types.JobConfig
contents, err := ioutil.ReadFile(filePath)
if err != nil {
return nil, fmt.Errorf("error reading job YAML %s: %v", filePath, err)
}
err = yaml.Unmarshal(contents, &jobConfig)
if err != nil {
return nil, fmt.Errorf("error unmarshaling contents of file %s: %v", filePath, err)
}
jobList[fileName] = jobConfig
}
}
return jobList, nil
}