public AzurePipelines.Job[] ProcessJobFromPipelineRootV2(string poolYaml, string strategyYaml, string stepsYaml) { Pool pool = null; if (poolYaml != null) { GeneralProcessing gp = new GeneralProcessing(_verbose); pool = gp.ProcessPoolV2(poolYaml); } AzurePipelines.Strategy strategy = null; try { //Most often, the pool will be in this structure strategy = GenericObjectSerialization.DeserializeYaml <AzurePipelines.Strategy>(strategyYaml); } catch (Exception ex) { ConversionUtility.WriteLine($"DeserializeYaml<AzurePipelines.Strategy>(strategyYaml) swallowed an exception: " + ex.Message, _verbose); } AzurePipelines.Step[] steps = null; if (stepsYaml != null) { try { steps = GenericObjectSerialization.DeserializeYaml <AzurePipelines.Step[]>(stepsYaml); } catch (Exception ex) { ConversionUtility.WriteLine($"DeserializeYaml<AzurePipelines.Step[]>(stepsYaml) swallowed an exception: " + ex.Message, _verbose); } } AzurePipelines.Job job = new AzurePipelines.Job { pool = pool, strategy = strategy, steps = steps }; //Don't add the build name unless there is content if (job.pool != null || job.strategy != null || steps != null) { AzurePipelines.Job[] jobs = new AzurePipelines.Job[1]; job.job = "build"; jobs[0] = job; return(jobs); } else { return(null); } }
public AzurePipelines.Job[] ExtractAzurePipelinesJobsV2(JToken jobsJson, string strategyYaml) { GeneralProcessing gp = new GeneralProcessing(_verbose); AzurePipelines.Job[] jobs = new AzurePipelines.Job[jobsJson.Count()]; if (jobsJson != null) { int i = 0; foreach (JToken jobJson in jobsJson) { AzurePipelines.Job job = new AzurePipelines.Job { job = jobJson["job"]?.ToString(), deployment = jobJson["deployment"]?.ToString(), displayName = jobJson["displayName"]?.ToString(), template = jobJson["template"]?.ToString() }; if (jobJson["pool"] != null) { job.pool = gp.ProcessPoolV2(jobJson["pool"].ToString()); } if (jobJson["strategy"] != null) { job.strategy = gp.ProcessStrategyV2(jobJson["strategy"].ToString()); } else if (strategyYaml != null) { job.strategy = gp.ProcessStrategyV2(strategyYaml); } if (jobJson["dependsOn"] != null) { job.dependsOn = gp.ProcessDependsOnV2(jobJson["dependsOn"].ToString()); } if (jobJson["condition"] != null) { job.condition = ConditionsProcessing.TranslateConditions(jobJson["condition"].ToString()); } if (jobJson["environment"] != null) { job.environment = gp.ProcessEnvironmentV2(jobJson["environment"].ToString()); } if (jobJson["timeoutInMinutes"] != null) { int.TryParse(jobJson["timeoutInMinutes"].ToString(), out int timeOut); if (timeOut > 0) { job.timeoutInMinutes = timeOut; } } if (jobJson["continueOnError"] != null) { bool.TryParse(jobJson["continueOnError"].ToString(), out bool continueOnError); job.continueOnError = continueOnError; } if (jobJson["variables"] != null) { VariablesProcessing vp = new VariablesProcessing(_verbose); job.variables = vp.ProcessParametersAndVariablesV2(null, jobJson["variables"].ToString()); } if (jobJson["steps"] != null) { try { job.steps = GenericObjectSerialization.DeserializeYaml <AzurePipelines.Step[]>(jobJson["steps"].ToString()); } catch (Exception ex) { ConversionUtility.WriteLine($"DeserializeYaml<AzurePipelines.Step[]>(jobJson[\"steps\"].ToString() swallowed an exception: " + ex.Message, _verbose); } } jobs[i] = job; i++; } } return(jobs); }