Exemple #1
0
        public override void Import(IBuildImporterContext context)
        {
            var configurer = (JenkinsConfigurer)this.GetExtensionConfigurer();
            var importer   = new JenkinsArtifactImporter(configurer, this, context)
            {
                ArtifactName = this.ArtifactName,
                BuildNumber  = this.BuildNumber,
                JobName      = this.JobName
            };

            string jenkinsBuildNumber = importer.ImportAsync().Result();

            if (jenkinsBuildNumber != null)
            {
                this.LogDebug("Creating $JenkinsBuildNumber variable...");
                DB.Variables_CreateOrUpdateVariableDefinition(
                    Variable_Name: "JenkinsBuildNumber",
                    Environment_Id: null,
                    ServerRole_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
                    );
            }
        }
Exemple #2
0
        public override void Import(IBuildImporterContext context)
        {
            var configurer = (TfsConfigurer)this.GetExtensionConfigurer();

            string buildNumber = VsoArtifactImporter.DownloadAndImportAsync(
                configurer,
                this,
                this.TeamProject,
                this.TfsBuildNumber,
                this.BuildDefinition,
                new ArtifactIdentifier(context.ApplicationId, context.ReleaseNumber, context.BuildNumber, context.DeployableId, this.ArtifactName)
                ).Result();

            if (this.CreateBuildNumberVariable)
            {
                this.LogDebug($"Setting $TfsBuildNumber build variable to {buildNumber}...");
                DB.Variables_CreateOrUpdateVariableDefinition(
                    Variable_Name: "TfsBuildNumber",
                    Environment_Id: null,
                    ServerRole_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: buildNumber,
                    Sensitive_Indicator: false
                    );

                this.LogInformation("$TfsBuildNumber build variable set to: " + buildNumber);
            }
        }
Exemple #3
0
        public override void Import(IBuildImporterContext context)
        {
            var configurer = this.GetExtensionConfigurer();
            var importer   = new TeamCityArtifactImporter(configurer, this, context)
            {
                ArtifactName         = this.ArtifactName,
                BranchName           = this.GetBranchName(configurer),
                BuildConfigurationId = this.BuildConfigurationId,
                BuildNumber          = this.BuildNumber
            };
            string teamCityBuildNumber = importer.ImportAsync().Result();

            this.LogDebug($"TeamCity build number resolved to {teamCityBuildNumber}, creating $TeamCityBuildNumber variable...");

            DB.Variables_CreateOrUpdateVariableDefinition(
                "TeamCityBuildNumber",
                Application_Id: context.ApplicationId,
                Release_Number: context.ReleaseNumber,
                Build_Number: context.BuildNumber,
                Value_Text: teamCityBuildNumber,
                Sensitive_Indicator: false,
                Environment_Id: null,
                ServerRole_Id: null,
                Server_Id: null,
                ApplicationGroup_Id: null,
                Execution_Id: null,
                Promotion_Id: null,
                Deployable_Id: null
                );
        }
Exemple #4
0
 private static void SetBuildVariable(IBuildImporterContext context, string variableName, string variableValue)
 {
     DB.Variables_CreateOrUpdateVariableDefinition(
         Variable_Name: variableName,
         Environment_Id: null,
         ServerRole_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,
         Value_Text: variableValue,
         Sensitive_Indicator: false,
         Promotion_Id: null
         );
 }
Exemple #5
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
                );
        }
        public override void Import(IBuildImporterContext context)
        {
            var configurer = (TfsConfigurer)this.GetExtensionConfigurer();

            this.LogDebug("Searching for build {0} for team project {1} definition {2}...", this.TfsBuildNumber, this.TeamProject, this.BuildDefinition);
            var tfsBuild = configurer.GetBuildInfo(this.TeamProject, this.BuildDefinition, this.TfsBuildNumber, this.IncludeUnsuccessful);

            if (tfsBuild == null)
            {
                this.LogError("Query did not return any builds.");
                return;
            }

            this.LogInformation("TFS Build Number: {0}", tfsBuild.BuildNumber);

            if (string.IsNullOrWhiteSpace(tfsBuild.DropLocation))
            {
                this.LogError("TFS configuration error: the selected build definition does not have a drop location specified.");
                return;
            }

            this.LogInformation("Drop location: {0}", tfsBuild.DropLocation);

            using (var agent = Util.Agents.CreateAgentFromId(configurer.ServerId))
            {
                var fileOps = agent.GetService<IFileOperationsExecuter>();

                this.LogDebug("Querying drop location...");
                var directoryResult = Util.Files.GetDirectoryEntry(
                    new GetDirectoryEntryCommand
                    {
                        Path = tfsBuild.DropLocation,
                        Recurse = true,
                        IncludeRootPath = true
                    }
                ).Entry;

                var matches = Util.Files.Comparison.GetMatches(tfsBuild.DropLocation, directoryResult, new[] { "*" })
                    .Where(e => !IsSamePath(e.Path, tfsBuild.DropLocation))
                    .ToList();

                if (!matches.Any())
                {
                    this.LogWarning("No files were found in the drop folder.");
                    return;
                }

                this.LogDebug("Creating {0} artifact...", this.ArtifactName);
                var artifactId = new ArtifactIdentifier(context.ApplicationId, context.ReleaseNumber, context.BuildNumber, context.DeployableId, this.ArtifactName);
                using (var artifact = new ArtifactBuilder(artifactId))
                {
                    artifact.RootPath = tfsBuild.DropLocation;

                    foreach (var match in matches)
                        artifact.Add(match, fileOps);

                    artifact.Commit();
                }
            }

            this.LogDebug("Creating $TfsBuildNumber variable...");
            StoredProcs.Variables_CreateOrUpdateVariableDefinition(
                Variable_Name: "TfsBuildNumber",
                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,
                Value_Text: tfsBuild.BuildNumber,
                Sensitive_Indicator: YNIndicator.No
            ).Execute();
        }
Exemple #7
0
        public override void Import(IBuildImporterContext context)
        {
            var configurer = (TfsConfigurer)this.GetExtensionConfigurer();

            this.LogDebug($"Searching for build {this.TfsBuildNumber} for team project {this.TeamProject} definition {this.BuildDefinition}...");
            var tfsBuild = configurer.GetBuildInfo(this.TeamProject, this.BuildDefinition, this.TfsBuildNumber, this.IncludeUnsuccessful);

            if (tfsBuild == null)
            {
                this.LogError("Query did not return any builds.");
                return;
            }

            this.LogInformation("TFS Build Number: " + tfsBuild.BuildNumber);

            if (string.IsNullOrWhiteSpace(tfsBuild.DropLocation))
            {
                this.LogError("TFS configuration error: the selected build definition does not have a drop location specified.");
                return;
            }

            this.LogInformation("Drop location: " + tfsBuild.DropLocation);

            var agent = configurer.ServerId != null?BuildMasterAgent.Create((int)configurer.ServerId) : BuildMasterAgent.CreateLocalAgent();

            using (agent)
            {
                var fileOps = agent.GetService <IFileOperationsExecuter>();

                this.LogDebug("Querying drop location...");

                var directoryResult = fileOps.GetDirectoryEntry(
                    new GetDirectoryEntryCommand
                {
                    Path            = tfsBuild.DropLocation,
                    Recurse         = true,
                    IncludeRootPath = true
                }
                    );
                var exception = directoryResult.Exceptions.FirstOrDefault();
                if (exception != null)
                {
                    throw exception;
                }

                var matches = Util.Files.Comparison.GetMatches(tfsBuild.DropLocation, directoryResult.Entry, new[] { "*" })
                              .Where(e => !IsSamePath(e.Path, tfsBuild.DropLocation))
                              .ToList();

                if (!matches.Any())
                {
                    this.LogWarning("No files were found in the drop folder.");
                    return;
                }

                this.LogDebug($"Creating {this.ArtifactName} artifact...");
                var artifactId = new ArtifactIdentifier(context.ApplicationId, context.ReleaseNumber, context.BuildNumber, context.DeployableId, this.ArtifactName);
                using (var artifact = new ArtifactBuilder(artifactId))
                {
                    artifact.RootPath = tfsBuild.DropLocation;

                    foreach (var match in matches)
                    {
                        artifact.Add(match, fileOps);
                    }

                    artifact.Commit();
                }
            }

            if (this.CreateBuildNumberVariable)
            {
                this.LogDebug($"Setting $TfsBuildNumber build variable to {tfsBuild.BuildNumber}...");
                DB.Variables_CreateOrUpdateVariableDefinition(
                    Variable_Name: "TfsBuildNumber",
                    Environment_Id: null,
                    ServerRole_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: tfsBuild.BuildNumber,
                    Sensitive_Indicator: YNIndicator.No
                    );

                this.LogInformation("$TfsBuildNumber build variable set to: " + tfsBuild.BuildNumber);
            }
        }
Exemple #8
0
        public override void Import(IBuildImporterContext context)
        {
            var configurer = (NuGetConfigurer)this.GetExtensionConfigurer();

            if (configurer.AlwaysClearNuGetCache)
            {
                this.LogDebug("Clearing NuGet cache...");
                if (NuGetConfigurer.ClearCache())
                {
                    this.LogDebug("Cache cleared!");
                }
                else
                {
                    this.LogWarning("Error clearing cache; a file may be locked.");
                }
            }

            var nugetExe = configurer != null ? configurer.NuGetExe : null;

            if (string.IsNullOrEmpty(nugetExe))
            {
                nugetExe = Path.Combine(Path.GetDirectoryName(typeof(NuGetBuildImporter).Assembly.Location), "nuget.exe");
            }

            var packageSource = Util.CoalesceStr(this.PackageSource, configurer != null ? configurer.PackageSource : null);

            var args = "install \"" + this.PackageId + "\" -ExcludeVersion -NoCache";

            if (!string.IsNullOrEmpty(this.PackageVersion))
            {
                args += " -Version \"" + this.PackageVersion + "\"";
            }
            if (this.IncludePrerelease)
            {
                args += " -Prerelease";
            }
            if (!string.IsNullOrEmpty(packageSource))
            {
                args += " -Source \"" + packageSource + "\"";
            }

            var tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            try
            {
                Directory.CreateDirectory(tempPath);

                args += " -OutputDirectory \"" + tempPath + "\"";

                if (!string.IsNullOrWhiteSpace(this.AdditionalArguments))
                {
                    args += " " + this.AdditionalArguments;
                }

                this.LogDebug($"Executing {nugetExe} {args}");
                this.LogInformation("Executing NuGet...");

                using (var process = new LocalProcess(new RemoteProcessStartInfo {
                    FileName = nugetExe, Arguments = args
                }))
                {
                    process.OutputDataReceived += this.Process_OutputDataReceived;
                    process.ErrorDataReceived  += this.Process_ErrorDataReceived;
                    process.Start();
                    process.WaitForExit();

                    if (process.ExitCode != 0)
                    {
                        this.LogError($"NuGet failed with exit code {process.ExitCode}.");
                        return;
                    }
                }

                this.LogInformation("NuGet indicated successful package install.");

                var packageRootPath = Path.Combine(tempPath, this.PackageId);
                var artifactName    = this.PackageId;

                if (this.CaptureIdAndVersion || this.IncludeVersionInArtifactName)
                {
                    try
                    {
                        var nupkgPath = Path.Combine(packageRootPath, this.PackageId + ".nupkg");
                        this.LogDebug($"Attempting to gather metadata from {nupkgPath}...");
                        var nuspec = NuGetPackage.ReadFromNupkgFile(nupkgPath);

                        var packageId      = nuspec.Id;
                        var packageVersion = nuspec.Version.OriginalString;

                        if (this.CaptureIdAndVersion)
                        {
                            this.LogDebug("Setting $ImportedPackageId = " + packageId);
                            SetBuildVariable(context, "ImportedPackageId", packageId);

                            this.LogDebug("Setting $ImportedPackageVersion = " + packageVersion);
                            SetBuildVariable(context, "ImportedPackageVersion", packageVersion);
                        }

                        if (this.IncludeVersionInArtifactName)
                        {
                            artifactName = packageId + "." + packageVersion;
                        }
                    }
                    catch (Exception ex)
                    {
                        this.LogError("Could not read package metadata: " + ex.ToString());
                        return;
                    }
                }

                var rootCapturePath = Path.Combine(packageRootPath, (this.PackageArtifactRoot ?? string.Empty).Replace('/', '\\').TrimStart('/', '\\'));
                this.LogDebug($"Capturing files in {rootCapturePath}...");

                var rootEntry = Util.Files.GetDirectoryEntry(
                    new GetDirectoryEntryCommand
                {
                    Path            = rootCapturePath,
                    IncludeRootPath = true,
                    Recurse         = true
                }
                    ).Entry;

                using (var agent = BuildMasterAgent.CreateLocalAgent())
                {
                    var fileOps    = agent.GetService <IFileOperationsExecuter>();
                    var matches    = Util.Files.Comparison.GetMatches(rootCapturePath, rootEntry, new[] { "!\\" + this.PackageId + ".nupkg", "*" });
                    var artifactId = new ArtifactIdentifier(context.ApplicationId, context.ReleaseNumber, context.BuildNumber, context.DeployableId, artifactName);

                    this.LogInformation($"Creating artifact {artifactName}...");
                    using (var artifact = new ArtifactBuilder(artifactId))
                    {
                        artifact.RootPath = rootCapturePath;

                        foreach (var match in matches)
                        {
                            artifact.Add(match, fileOps);
                        }

                        artifact.Commit();
                    }

                    this.LogInformation("Artifact created.");
                }
            }
            finally
            {
                try
                {
                    DirectoryEx.Delete(tempPath);
                }
                catch
                {
                }
            }
        }