Example #1
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));
        }
Example #2
0
        public async Task AssociateArtifactAsync(
            IExecutionContext context,
            IAsyncCommandContext commandContext,
            VssConnection connection,
            Guid projectId,
            string name,
            string type,
            string data,
            Dictionary <string, string> propertiesDictionary,
            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));

            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, type, data, propertiesDictionary, cancellationToken);

            context.Output(StringUtil.Loc("AssociateArtifactWithRelease", artifact.Id, releaseId));
        }