Example #1
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));
        }
        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)
        {
            FileContainerServer fileContainerHelper = new FileContainerServer(connection, projectId, containerId, containerPath);
            long size = await fileContainerHelper.CopyToContainerAsync(context, source, cancellationToken);

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

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

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

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

            context.Output(StringUtil.Loc("AssociateArtifactWithBuild", artifact.Id, buildId));
        }
Example #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));
        }
Example #4
0
        private async Task UpdateBuildNumberAsync(
            IAsyncCommandContext context,
            VssConnection connection,
            Guid projectId,
            int buildId,
            string buildNumber,
            CancellationToken cancellationToken)
        {
            BuildServer buildServer = new BuildServer(connection, projectId);
            var         build       = await buildServer.UpdateBuildNumber(buildId, buildNumber, cancellationToken);

            context.Output(StringUtil.Loc("UpdateBuildNumberForBuild", build.BuildNumber, build.Id));
        }
Example #5
0
        private async Task AssociateArtifactAsync(
            IAsyncCommandContext context,
            VssConnection connection,
            Guid projectId,
            int buildId,
            string name,
            string type,
            string data,
            Dictionary <string, string> propertiesDictionary,
            CancellationToken cancellationToken)
        {
            BuildServer buildHelper = new BuildServer(connection, projectId);
            var         artifact    = await buildHelper.AssociateArtifact(buildId, name, type, data, propertiesDictionary, cancellationToken);

            context.Output(StringUtil.Loc("AssociateArtifactWithBuild", artifact.Id, buildId));
        }
Example #6
0
        private async Task AddBuildTagAsync(
            IAsyncCommandContext context,
            VssConnection connection,
            Guid projectId,
            int buildId,
            string buildTag,
            CancellationToken cancellationToken)
        {
            BuildServer buildServer = new BuildServer(connection, projectId);
            var         tags        = await buildServer.AddBuildTag(buildId, buildTag, cancellationToken);

            if (tags == null || !tags.Any(t => t.Equals(buildTag, StringComparison.OrdinalIgnoreCase)))
            {
                throw new Exception(StringUtil.Loc("BuildTagAddFailed", buildTag));
            }
            else
            {
                context.Output(StringUtil.Loc("BuildTagsForBuild", buildId, String.Join(", ", tags)));
            }
        }
Example #7
0
        private async Task AddBuildTagAsync(
            IAsyncCommandContext context,
            Uri projectCollection,
            VssCredentials credentials,
            Guid projectId,
            int buildId,
            string buildTag,
            CancellationToken cancellationToken)
        {
            BuildServer buildServer = new BuildServer(projectCollection, credentials, projectId);
            var         tags        = await buildServer.AddBuildTag(buildId, buildTag, cancellationToken);

            if (tags == null || !tags.Contains(buildTag))
            {
                throw new Exception(StringUtil.Loc("BuildTagAddFailed", buildTag));
            }
            else
            {
                context.Output(StringUtil.Loc("BuildTagsForBuild", buildId, String.Join(", ", tags)));
            }
        }
Example #8
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?buildId = context.Variables.Build_BuildId;

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

            context.Debug($"Associate artifact: {name} with build: {buildId.Value} at backend.");
            BuildServer buildHelper = new BuildServer(connection, projectId);
            var         artifact    = await buildHelper.AssociateArtifact(buildId.Value, name, type, data, propertiesDictionary, cancellationToken);

            context.Output(StringUtil.Loc("AssociateArtifactWithBuild", artifact.Id, buildId));
        }
        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));
        }
 private async Task AssociateArtifactAsync(
     IAsyncCommandContext context,
     Uri projectCollection,
     VssCredentials credentials,
     Guid projectId,
     int buildId,
     string name,
     string type,
     string data,
     Dictionary<string, string> propertiesDictionary,
     CancellationToken cancellationToken)
 {
     BuildServer buildHelper = new BuildServer(projectCollection, credentials, projectId);
     var artifact = await buildHelper.AssociateArtifact(buildId, name, type, data, propertiesDictionary, cancellationToken);
     context.Output(StringUtil.Loc("AssociateArtifactWithBuild", artifact.Id, buildId));
 }
        private async Task AddBuildTagAsync(
            IAsyncCommandContext context,
            Uri projectCollection,
            VssCredentials credentials,
            Guid projectId,
            int buildId,
            string buildTag,
            CancellationToken cancellationToken)
        {
            BuildServer buildServer = new BuildServer(projectCollection, credentials, projectId);
            var tags = await buildServer.AddBuildTag(buildId, buildTag, cancellationToken);

            if (tags == null || !tags.Contains(buildTag))
            {
                throw new Exception(StringUtil.Loc("BuildTagAddFailed", buildTag));
            }
            else
            {
                context.Output(StringUtil.Loc("BuildTagsForBuild", buildId, String.Join(", ", tags)));
            }
        }
 private async Task UpdateBuildNumberAsync(
     IAsyncCommandContext context,
     Uri projectCollection,
     VssCredentials credentials,
     Guid projectId,
     int buildId,
     string buildNumber,
     CancellationToken cancellationToken)
 {
     BuildServer buildServer = new BuildServer(projectCollection, credentials, projectId);
     var build = await buildServer.UpdateBuildNumber(buildId, buildNumber, cancellationToken);
     context.Output(StringUtil.Loc("UpdateBuildNumberForBuild", build.BuildNumber, build.Id));
 }