Esempio n. 1
0
        protected override void CreateChildControls()
        {
            var client = new JenkinsClient((JenkinsConfigurer)this.GetExtensionConfigurer());

            this.txtArtifactName = new ValidatingTextBox {
                DefaultText = "download all artifacts"
            };

            this.txtJob = new ValidatingTextBox
            {
                Required = true
            };

            this.txtBuildNumber = new ValidatingTextBox
            {
                Required           = true,
                AutoCompleteValues = new[] { "lastBuild", "lastCompletedBuild", "lastStableBuild", "lastSuccessfulBuild" }
            };

            this.chkExtractFilesToTargetDirectory = new CheckBox {
                Text = "Extract archive.zip when downloading all artifacts", Checked = true
            };

            this.Controls.Add(
                new SlimFormField("Artifact filter:", this.txtArtifactName),
                new SlimFormField("Job name:", this.txtJob),
                new SlimFormField("Build number", this.txtBuildNumber),
                new SlimFormField("Download options:", this.chkExtractFilesToTargetDirectory)
                );
        }
Esempio n. 2
0
        private Task <string> ResolveJenkinsBuildNumber()
        {
            if (AH.ParseInt(this.BuildNumber) != null)
            {
                return(Task.FromResult(this.BuildNumber));
            }

            this.Logger.LogDebug($"Build number is not an integer, resolving special build number \"{this.BuildNumber}\"...");
            var client = new JenkinsClient(this.ConnectionInfo, this.Logger);

            return(client.GetSpecialBuildNumberAsync(this.JobName, this.BuildNumber));
        }
Esempio n. 3
0
        protected override string ProcessRemoteCommand(string name, string[] args)
        {
            var client = new JenkinsClient((JenkinsConfigurer)this.GetExtensionConfigurer(), this);

            if (name == "next")
            {
                return(client.GetNextBuildNumberAsync(this.JobName).Result());
            }

            else if (name == "build")
            {
                client.TriggerBuildAsync(this.JobName, this.AdditionalParameters).WaitAndUnwrapExceptions();
                return(null);
            }
            else if (name == "is-building")
            {
                var build = client.GetBuildInfoAsync(this.JobName, args[0]).Result();
                if (build == null)
                {
                    return(bool.TrueString);
                }
                else
                {
                    return(build.Building.ToString());
                }
            }

            else if (name == "get-status")
            {
                return(client.GetBuildInfoAsync(this.JobName, args[0]).Result().Result);
            }

            else
            {
                throw new ArgumentOutOfRangeException("name");
            }
        }
Esempio n. 4
0
        public async Task <string> ImportAsync()
        {
            this.Logger.LogInformation($"Importing artifact \"{this.ArtifactName}\" from Jenkins...");

            string zipFileName        = null;
            string jenkinsBuildNumber = await this.ResolveJenkinsBuildNumber().ConfigureAwait(false);

            if (string.IsNullOrEmpty(jenkinsBuildNumber))
            {
                this.Logger.LogError($"An error occurred attempting to resolve Jenkins build number \"{this.BuildNumber}\". "
                                     + $"This can mean that the special build type was not found, there are no builds for job \"{this.JobName}\", "
                                     + "or that the job was not found or is disabled."
                                     );

                return(null);
            }

            try
            {
                this.Logger.LogInformation($"Importing {this.ArtifactName} from {this.JobName}...");
                var client = new JenkinsClient(this.ConnectionInfo, this.Logger);

                zipFileName = Path.GetTempFileName();
                this.Logger.LogDebug("Temp file: " + zipFileName);

                this.Logger.LogDebug("Downloading artifact...");
                await client.DownloadArtifactAsync(this.JobName, jenkinsBuildNumber, zipFileName).ConfigureAwait(false);

                this.Logger.LogInformation("Artifact downloaded.");

                using (var file = FileEx.Open(zipFileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    await Artifact.CreateArtifactAsync(
                        (int)this.Context.ApplicationId,
                        this.Context.ReleaseNumber,
                        this.Context.BuildNumber,
                        this.Context.DeployableId,
                        this.Context.ExecutionId,
                        TrimWhitespaceAndZipExtension(this.ArtifactName),
                        file,
                        true
                        ).ConfigureAwait(false);
                }
            }
            finally
            {
                try
                {
                    if (zipFileName != null)
                    {
                        this.Logger.LogDebug("Removing temp file...");
                        FileEx.Delete(zipFileName);
                    }
                }
                catch (Exception ex)
                {
                    this.Logger.LogWarning("Error deleting temp file:" + ex.Message);
                }
            }

            this.Logger.LogInformation(this.ArtifactName + " artifact imported.");

            return(jenkinsBuildNumber);
        }
Esempio n. 5
0
        private static void DownloadSingleArtifactInternal(JenkinsConfigurer configurer, string job, string buildNumber, string fileName, JenkinsBuildArtifact artifact, ILogger logger)
        {
            var client = new JenkinsClient(configurer, logger);

            client.DownloadSingleArtifactAsync(job, buildNumber, fileName, artifact).WaitAndUnwrapExceptions();
        }
Esempio n. 6
0
        public override void Import(IBuildImporterContext context)
        {
            string zipFileName        = null;
            string jenkinsBuildNumber = this.ResolveJenkinsBuildNumber();

            if (string.IsNullOrEmpty(jenkinsBuildNumber))
            {
                this.LogError("An error occurred attempting to resolve Jenkins build number \"{0}\". This can mean that "
                              + "the special build type was not found, there are no builds for job \"{1}\", or that the job was not found or is disabled.",
                              this.BuildNumber,
                              this.JobName);
                return;
            }

            try
            {
                this.LogInformation("Importing {0} from {1}...", this.ArtifactName, this.JobName);
                var client = new JenkinsClient((JenkinsConfigurer)this.GetExtensionConfigurer(), this);

                zipFileName = Path.GetTempFileName();
                this.LogDebug("Temp file: " + zipFileName);

                this.LogDebug("Downloading artifact...");
                client.DownloadArtifact(this.JobName, jenkinsBuildNumber, zipFileName);
                this.LogInformation("Artifact downloaded.");

                using (var agent = Util.Agents.CreateLocalAgent())
                {
                    ArtifactBuilder.ImportZip(
                        new ArtifactIdentifier(
                            context.ApplicationId,
                            context.ReleaseNumber,
                            context.BuildNumber,
                            context.DeployableId,
                            this.ArtifactName),
                        agent.GetService <IFileOperationsExecuter>(),
                        new FileEntryInfo(Path.GetFileName(zipFileName), zipFileName)
                        );
                }
            }
            finally
            {
                try
                {
                    if (zipFileName != null)
                    {
                        File.Delete(zipFileName);
                    }
                }
                catch (Exception ex)
                {
                    this.LogWarning("Error deleting temp file:" + ex.Message);
                }
            }

            this.LogDebug("Creating $JenkinsBuildNumber variable...");
            DB.Variables_CreateOrUpdateVariableDefinition(
                Variable_Name: "JenkinsBuildNumber",
                Environment_Id: null,
                Server_Id: null,
                ApplicationGroup_Id: null,
                Application_Id: context.ApplicationId,
                Deployable_Id: null,
                Release_Number: context.ReleaseNumber,
                Build_Number: context.BuildNumber,
                Execution_Id: null,
                Promotion_Id: null,
                Value_Text: jenkinsBuildNumber,
                Sensitive_Indicator: false
                );
        }