Example #1
0
        protected override async Task <object> RemoteExecuteAsync(IRemoteOperationExecutionContext context)
        {
            this.LogInformation($"Downloading TFS artifact {this.ArtifactName} with build number \"{this.BuildNumber ?? "latest"}\" from TFS...");

            var downloader = new ArtifactDownloader(this, this);

            using (var artifact = await downloader.DownloadAsync(this.TeamProject, this.BuildNumber, this.BuildDefinition, this.ArtifactName).ConfigureAwait(false))
            {
                string targetDirectory = context.ResolvePath(this.TargetDirectory);
                if (this.ExtractFilesToTargetDirectory)
                {
                    this.LogDebug("Extracting artifact files to: " + targetDirectory);
                    AH.ExtractZip(artifact.Content, targetDirectory);
                }
                else
                {
                    string path = PathEx.Combine(targetDirectory, artifact.FileName);
                    this.LogDebug("Saving artifact as zip file to: " + path);

                    using (var file = FileEx.Open(path, FileMode.Create, FileAccess.Write, FileShare.None, FileOptions.Asynchronous | FileOptions.SequentialScan))
                    {
                        await artifact.Content.CopyToAsync(file).ConfigureAwait(false);
                    }
                }
            }

            this.LogInformation("Artifact downloaded.");

            return(null);
        }
Example #2
0
        public static async Task <string> DownloadAndImportAsync(IVsoConnectionInfo connectionInfo, ILogSink logger, string teamProject, string buildNumber, string buildDefinitionName, IOperationExecutionContext context, string artifactName)
        {
            var downloader = new ArtifactDownloader(connectionInfo, logger);

            using (var artifact = await downloader.DownloadAsync(teamProject, buildNumber, buildDefinitionName, artifactName).ConfigureAwait(false))
            {
                logger.LogInformation("Downloading artifact file from VSO and importing into BuildMaster artifact library...");

                var shim = new BuildMasterContextShim(context);

                await SDK.CreateArtifactAsync(
                    applicationId : shim.ApplicationId,
                    releaseNumber : shim.ReleaseNumber,
                    buildNumber : shim.BuildNumber,
                    deployableId : shim.DeployableId,
                    executionId : null,
                    artifactName : artifact.Name,
                    artifactData : artifact.Content,
                    overwrite : true
                    ).ConfigureAwait(false);

                logger.LogInformation($"{artifact.Name} artifact imported.");

                return(artifact.BuildNumber);
            }
        }