public IEnumerable <Metadata> Transform(Metadata metadata) { if (metadata.Kref != null && metadata.Kref.Source == "jenkins") { var json = metadata.Json(); Log.InfoFormat("Executing Jenkins transformation with {0}", metadata.Kref); Log.DebugFormat("Input metadata:{0}{1}", Environment.NewLine, json); JenkinsOptions options = json["x_netkan_jenkins"]?.ToObject <JenkinsOptions>() ?? new JenkinsOptions(); JenkinsRef jRef = new JenkinsRef(metadata.Kref); var versions = _api.GetAllBuilds(jRef, options); if (_releases.HasValue) { versions = versions.Take(_releases.Value); } foreach (JenkinsBuild build in versions) { yield return(TransformOne(metadata, metadata.Json(), build, options)); } } else { yield return(metadata); } }
public void CopyFrom(FlubuConfigurationBuilder builder) { TravisOptions = builder.TravisOptions; AzurePipelineOptions = builder.AzurePipelineOptions; AppVeyorOptions = builder.AppVeyorOptions; GitHubActionsOptions = builder.GitHubActionsOptions; JenkinsOptions = builder.JenkinsOptions; }
public void FromOptions(JenkinsOptions options) { switch (options.FlubuToolType) { case FlubuToolType.GlobalTool: FlubuCommand = "flubu"; break; case FlubuToolType.LocalTool: case FlubuToolType.CliTool: FlubuCommand = "dotnet flubu"; break; } Options = options.Options; if (options.Environment != null && options.Environment.Count != 0) { Environment = options.Environment; } if (!options.CustomStagesBeforeTargets.IsNullOrEmpty()) { Stages.AddRange(options.CustomStagesBeforeTargets); } else { Stages = new List <Stage>(); } foreach (var targetName in options.TargetNames) { Stage stage = new Stage { Name = targetName, }; if (!string.IsNullOrEmpty(options.WorkingDirectory)) { stage.WorkingDirectory = options.WorkingDirectory; } var command = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "bat" : "sh"; stage.Steps.Add($"{command} '{FlubuCommand} {targetName} --nd'"); Stages.Add(stage); } if (!options.CustomStagesAfterTargets.IsNullOrEmpty()) { Stages.AddRange(options.CustomStagesAfterTargets); } if (!options.JenkinsPosts.IsNullOrEmpty()) { Post = options.JenkinsPosts; } }
static int Main(string[] args) { int retVal = 0; Parser.Default.ParseArguments <Options>(args) .WithNotParsed(errors => { foreach (var error in errors) { Console.WriteLine(error.ToString()); } retVal = 1; }) .WithParsed(options => { try { using (var jenkinsClient = new JenkinsClient(JenkinsOptions.Current())) { if (options.Parameters.Count() == 0) { jenkinsClient.SubmitJobAsync(options.JobName) .Wait(); } else { IEnumerable <(string, string)> parameters = options.Parameters.Select(p => { string[] parts = p.Split('='); if (parts.Length != 2) { throw new Exception("parameter name-value pair must be separated by an equals sign"); } return(parts[0], parts[1]); }); jenkinsClient.SubmitParameterizedJob(options.JobName, parameters) .Wait(); } } } catch (Exception e) { do { Console.WriteLine(e.Message); e = e.InnerException; }while (e != null); retVal = 1; } }); return(retVal); }
public FlubuConfiguration( TravisOptions travisOptions, AzurePipelineOptions azureOptions, GitHubActionsOptions gitHubActionsOptions, AppVeyorOptions appVeyorOptions, JenkinsOptions jenkinsOptions) { TravisOptions = travisOptions; AzurePipelineOptions = azureOptions; GitHubActionsOptions = gitHubActionsOptions; AppVeyorOptions = appVeyorOptions; JenkinsOptions = jenkinsOptions; }
public void FromOptions(JenkinsOptions options) { Options = options.Options; if (options.Environment != null && options.Environment.Count != 0) { Environment = options.Environment; } if (!options.CustomStagesBeforeTargets.IsNullOrEmpty()) { Stages.AddRange(options.CustomStagesBeforeTargets); } else { Stages = new List <Stage>(); } foreach (var targetName in options.TargetNames) { Stage stage = new Stage { Name = targetName, }; if (!string.IsNullOrEmpty(options.WorkingDirectory)) { stage.WorkingDirectory = options.WorkingDirectory; } stage.Steps.Add($"flubu {targetName} --nd"); Stages.Add(stage); } if (!options.CustomStagesAfterTargets.IsNullOrEmpty()) { Stages.AddRange(options.CustomStagesAfterTargets); } if (!options.JenkinsPosts.IsNullOrEmpty()) { Post = options.JenkinsPosts; } }
public IEnumerable <Metadata> Transform(Metadata metadata, TransformOptions opts) { if (metadata.Kref != null && metadata.Kref.Source == "jenkins") { var json = metadata.Json(); Log.InfoFormat("Executing Jenkins transformation with {0}", metadata.Kref); Log.DebugFormat("Input metadata:{0}{1}", Environment.NewLine, json); JenkinsOptions options = json["x_netkan_jenkins"]?.ToObject <JenkinsOptions>() ?? new JenkinsOptions(); JenkinsRef jRef = new JenkinsRef(metadata.Kref); var versions = _api.GetAllBuilds(jRef, options); if (opts.SkipReleases.HasValue) { versions = versions.Skip(opts.SkipReleases.Value); } if (opts.Releases.HasValue) { versions = versions.Take(opts.Releases.Value); } bool returnedAny = false; foreach (JenkinsBuild build in versions) { returnedAny = true; yield return(TransformOne(metadata, metadata.Json(), build, options)); } if (!returnedAny) { Log.WarnFormat("No releases found for {0}", jRef.BaseUri); yield return(metadata); } } else { yield return(metadata); } }
private Metadata TransformOne(Metadata metadata, JObject json, JenkinsBuild build, JenkinsOptions options) { JenkinsArtifact[] artifacts = build.Artifacts .Where(a => options.AssetMatchPattern.IsMatch(a.FileName)) .ToArray(); switch (artifacts.Length) { case 1: JenkinsArtifact artifact = artifacts.Single(); string download = Uri.EscapeUriString( $"{build.Url}artifact/{artifact.RelativePath}" ); Log.DebugFormat("Using download URL: {0}", download); json.SafeAdd("download", download); if (options.UseFilenameVersion) { Log.DebugFormat("Using filename as version: {0}", artifact.FileName); json.SafeAdd("version", artifact.FileName); } // Make sure resources exist. if (json["resources"] == null) { json["resources"] = new JObject(); } var resourcesJson = (JObject)json["resources"]; resourcesJson.SafeAdd("ci", Uri.EscapeUriString(metadata.Kref.Id)); Log.DebugFormat("Transformed metadata:{0}{1}", Environment.NewLine, json); return(new Metadata(json)); case 0: throw new Exception("Could not find any matching artifacts"); default: throw new Exception("Found too many matching artifacts"); } }
public Metadata Transform(Metadata metadata) { if (metadata.Kref != null && metadata.Kref.Source == "jenkins") { var json = metadata.Json(); Log.InfoFormat("Executing Jenkins transformation with {0}", metadata.Kref); Log.DebugFormat("Input metadata:{0}{1}", Environment.NewLine, json); JenkinsOptions options = json["x_netkan_jenkins"]?.ToObject <JenkinsOptions>() ?? new JenkinsOptions(); JenkinsBuild build = _api.GetLatestBuild( new JenkinsRef(metadata.Kref), options ); JenkinsArtifact[] artifacts = build.Artifacts .Where(a => options.AssetMatchPattern.IsMatch(a.FileName)) .ToArray(); switch (artifacts.Length) { case 1: JenkinsArtifact artifact = artifacts.Single(); string download = Uri.EscapeUriString( $"{build.Url}artifact/{artifact.RelativePath}" ); Log.DebugFormat("Using download URL: {0}", download); json.SafeAdd("download", download); if (options.UseFilenameVersion) { Log.DebugFormat("Using filename as version: {0}", artifact.FileName); json.SafeAdd("version", artifact.FileName); } // Make sure resources exist. if (json["resources"] == null) { json["resources"] = new JObject(); } var resourcesJson = (JObject)json["resources"]; resourcesJson.SafeAdd("ci", Uri.EscapeUriString(metadata.Kref.Id)); Log.DebugFormat("Transformed metadata:{0}{1}", Environment.NewLine, json); return(new Metadata(json)); break; case 0: throw new Exception("Could not find any matching artifacts"); default: throw new Exception("Found too many matching artifacts"); } } return(metadata); }