public static async Task UploadArtifactAsync(
            IAsyncCommandContext context,
            VssConnection connection,
            Guid projectId,
            long containerId,
            string containerPath,
            int buildId,
            string name,
            string jobId,
            Dictionary <string, string> propertiesDictionary,
            string source,
            CancellationToken cancellationToken)
        {
            var fileContainerHelper = new FileContainerServer(connection, projectId, containerId, containerPath);
            var size = await fileContainerHelper.CopyToContainerAsync(context, source, cancellationToken);

            propertiesDictionary.Add(ArtifactUploadEventProperties.ArtifactSize, size.ToString());

            var fileContainerFullPath = StringUtil.Format($"#/{containerId}/{containerPath}");

            context.Output(StringUtil.Loc("UploadToFileContainer", source, fileContainerFullPath));

            var buildHelper = context.GetHostContext().GetService <IBuildServer>();
            await buildHelper.ConnectAsync(connection);

            var artifact = await buildHelper.AssociateArtifactAsync(buildId, projectId, name, jobId, ArtifactResourceTypes.Container, fileContainerFullPath, propertiesDictionary, cancellationToken);

            context.Output(StringUtil.Loc("AssociateArtifactWithBuild", artifact.Id, buildId));
        }
Exemplo n.º 2
0
        private async Task UploadArtifactAsync(
            IAsyncCommandContext context,
            Uri projectCollection,
            VssCredentials credentials,
            Guid projectId,
            long containerId,
            string containerPath,
            int buildId,
            string name,
            Dictionary <string, string> propertiesDictionary,
            string source,
            CancellationToken cancellationToken)
        {
            FileContainerServer fileContainerHelper = new FileContainerServer(projectCollection, credentials, projectId, containerId, containerPath);
            await fileContainerHelper.CopyToContainerAsync(context, source, cancellationToken);

            string fileContainerFullPath = StringUtil.Format($"#/{containerId}/{containerPath}");

            context.Output(StringUtil.Loc("UploadToFileContainer", source, fileContainerFullPath));

            BuildServer buildHelper = new BuildServer(projectCollection, credentials, projectId);
            var         artifact    = await buildHelper.AssociateArtifact(buildId, name, WellKnownArtifactResourceTypes.Container, fileContainerFullPath, propertiesDictionary, cancellationToken);

            context.Output(StringUtil.Loc("AssociateArtifactWithBuild", artifact.Id, buildId));
        }
Exemplo n.º 3
0
        public async Task UploadArtifactAsync(
            IExecutionContext context,
            IAsyncCommandContext commandContext,
            VssConnection connection,
            Guid projectId,
            string containerPath,
            string name,
            Dictionary <string, string> propertiesDictionary,
            string source,
            CancellationToken cancellationToken)
        {
            int?buildId = context.Variables.Build_BuildId;

            ArgUtil.NotNull(buildId, nameof(buildId));

            long?containerId = context.Variables.Build_ContainerId;

            ArgUtil.NotNull(containerId, nameof(containerId));

            context.Debug($"Upload artifact: {source} to server for build: {buildId.Value} at backend.");
            FileContainerServer fileContainerHelper = new FileContainerServer(connection, projectId, containerId.Value, containerPath);
            await fileContainerHelper.CopyToContainerAsync(commandContext, source, cancellationToken);

            string fileContainerFullPath = StringUtil.Format($"#/{containerId.Value}/{containerPath}");

            context.Output(StringUtil.Loc("UploadToFileContainer", source, fileContainerFullPath));

            BuildServer buildHelper = new BuildServer(connection, projectId);
            var         artifact    = await buildHelper.AssociateArtifact(buildId.Value, name, WellKnownArtifactResourceTypes.Container, fileContainerFullPath, propertiesDictionary, cancellationToken);

            context.Output(StringUtil.Loc("AssociateArtifactWithBuild", artifact.Id, buildId));
        }
Exemplo n.º 4
0
        public async Task UploadArtifactAsync(
            IExecutionContext context,
            IAsyncCommandContext commandContext,
            VssConnection connection,
            Guid projectId,
            string containerPath,
            string name,
            Dictionary <string, string> propertiesDictionary,
            string source,
            CancellationToken cancellationToken)
        {
            int?releaseId = context.Variables.Release_ReleaseId;

            ArgUtil.NotNull(releaseId, nameof(releaseId));

            int?releaseEnvironmentId = context.Variables.Release_ReleaseEnvironmentId;

            ArgUtil.NotNull(releaseId, nameof(releaseEnvironmentId));

            int?attempt = context.Variables.Release_Attempt;

            ArgUtil.NotNull(releaseId, nameof(attempt));

            long?containerId = context.Variables.Release_ContainerId;

            ArgUtil.NotNull(containerId, nameof(containerId));

            //var releaseContainerPath = releaseId + "/" + releaseEnvironmentId + "/" + context.Variables.Release_DeploymentId + "/" + containerPath;
            var releaseContainerPath = releaseId + "/" + containerPath; // No folder change in build artifacts

            context.Debug($"Upload artifact: {source} to server for release: {releaseId.Value} at backend.");
            FileContainerServer fileContainerHelper = new FileContainerServer(connection, projectId, containerId.Value, releaseContainerPath);
            await fileContainerHelper.CopyToContainerAsync(commandContext, source, cancellationToken);

            string fileContainerFullPath = StringUtil.Format($"#/{containerId.Value}/{releaseContainerPath}");

            context.Output(StringUtil.Loc("UploadToFileContainer", source, fileContainerFullPath));

            ServiceEndpoint vssEndpoint = context.Endpoints.FirstOrDefault(e => string.Equals(e.Name, ServiceEndpoints.SystemVssConnection, StringComparison.OrdinalIgnoreCase));

            ArgUtil.NotNull(vssEndpoint, nameof(vssEndpoint));
            ArgUtil.NotNull(vssEndpoint.Url, nameof(vssEndpoint.Url));

            context.Debug($"Connecting to {vssEndpoint.Url}/{projectId}");
            var releaseServer = new ReleaseServer(vssEndpoint.Url, ApiUtil.GetVssCredential(vssEndpoint), projectId);

            var artifact = await releaseServer.AssociateArtifact(releaseId.Value, releaseEnvironmentId.Value, Convert.ToInt32(context.Variables.Release_DeploymentId), name, WellKnownArtifactResourceTypes.Container, fileContainerFullPath, propertiesDictionary, cancellationToken);

            context.Output(StringUtil.Loc("AssociateArtifactWithRelease", artifact.Id, releaseId));
        }
Exemplo n.º 5
0
        public async Task PublishCodeCoverageFilesAsync(IAsyncCommandContext context, Guid projectId, long containerId, List<Tuple<string, string>> files, bool browsable, CancellationToken cancellationToken)
        {
            var publishCCTasks = files.Select(async file =>
            {
                var browsableProperty = (browsable) ? bool.TrueString : bool.FalseString;
                var artifactProperties = new Dictionary<string, string> {
                    { ArtifactUploadEventProperties.ContainerFolder, file.Item2},
                    { ArtifactUploadEventProperties.ArtifactName, file.Item2 },
                    { ArtifactAssociateEventProperties.ArtifactType, WellKnownArtifactResourceTypes.Container },
                    { ArtifactAssociateEventProperties.Browsable, browsableProperty },
                };

                FileContainerServer fileContainerHelper = new FileContainerServer(_connection.Uri, _connection.Credentials, projectId, containerId, file.Item2);
                await fileContainerHelper.CopyToContainerAsync(context, file.Item1, cancellationToken);
                string fileContainerFullPath = StringUtil.Format($"#/{containerId}/{file.Item2}");

                Build.BuildServer buildHelper = new Build.BuildServer(_connection.Uri, _connection.Credentials, projectId);
                var artifact = await buildHelper.AssociateArtifact(_buildId, file.Item2, WellKnownArtifactResourceTypes.Container, fileContainerFullPath, artifactProperties, cancellationToken);
                context.Output(StringUtil.Loc("PublishedCodeCoverageArtifact", file.Item1, file.Item2));
            });

            await Task.WhenAll(publishCCTasks);
        }
        private async Task UploadArtifactAsync(
            IAsyncCommandContext context,
            Uri projectCollection,
            VssCredentials credentials,
            Guid projectId,
            long containerId,
            string containerPath,
            int buildId,
            string name,
            Dictionary<string, string> propertiesDictionary,
            string source,
            CancellationToken cancellationToken)
        {
            FileContainerServer fileContainerHelper = new FileContainerServer(projectCollection, credentials, projectId, containerId, containerPath);
            await fileContainerHelper.CopyToContainerAsync(context, source, cancellationToken);
            string fileContainerFullPath = StringUtil.Format($"#/{containerId}/{containerPath}");
            context.Output(StringUtil.Loc("UploadToFileContainer", source, fileContainerFullPath));

            BuildServer buildHelper = new BuildServer(projectCollection, credentials, projectId);
            var artifact = await buildHelper.AssociateArtifact(buildId, name, WellKnownArtifactResourceTypes.Container, fileContainerFullPath, propertiesDictionary, cancellationToken);
            context.Output(StringUtil.Loc("AssociateArtifactWithBuild", artifact.Id, buildId));
        }