Beispiel #1
0
        private void CreateArtifactsFolder(IExecutionContext executionContext, string artifactsWorkingFolder)
        {
            Trace.Entering();

            RetryExecutor retryExecutor = new RetryExecutor();

            retryExecutor.ShouldRetryAction = (ex) =>
            {
                executionContext.Output(StringUtil.Loc("RMRetryingCreatingArtifactsDirectory", artifactsWorkingFolder, ex));
                Trace.Error(ex);

                return(true);
            };

            retryExecutor.Execute(
                () =>
            {
                executionContext.Output(StringUtil.Loc("RMCreatingArtifactsDirectory", artifactsWorkingFolder));

                var releaseFileSystemManager = HostContext.GetService <IReleaseFileSystemManager>();
                releaseFileSystemManager.EnsureEmptyDirectory(artifactsWorkingFolder, executionContext.CancellationToken);
            });

            executionContext.Output(StringUtil.Loc("RMCreatedArtifactsDirectory", artifactsWorkingFolder));
        }
Beispiel #2
0
        private ArtifactDefinition ConvertToArtifactDefinition(AgentArtifactDefinition agentArtifactDefinition, IExecutionContext executionContext, IArtifactExtension extension)
        {
            Trace.Entering();

            ArgUtil.NotNull(agentArtifactDefinition, nameof(agentArtifactDefinition));
            ArgUtil.NotNull(executionContext, nameof(executionContext));

            var artifactDefinition = new ArtifactDefinition
            {
                ArtifactType = agentArtifactDefinition.ArtifactType,
                Name         = agentArtifactDefinition.Name,
                Version      = agentArtifactDefinition.Version
            };

            RetryExecutor retryExecutor = new RetryExecutor();

            retryExecutor.ShouldRetryAction = (ex) =>
            {
                bool retry = true;
                if (ex is InvalidOperationException)
                {
                    retry = false;
                }
                else
                {
                    Trace.Warning(ex.ToString());
                }

                return(retry);
            };

            retryExecutor.Execute(
                () =>
            {
                artifactDefinition.Details = extension.GetArtifactDetails(executionContext, agentArtifactDefinition);
            });

            return(artifactDefinition);
        }
        private void CleanUpArtifactsFolder(IExecutionContext executionContext, string artifactsWorkingFolder)
        {
            Trace.Entering();

            RetryExecutor retryExecutor = new RetryExecutor();

            retryExecutor.ShouldRetryAction = (ex) =>
            {
                executionContext.Output(StringUtil.Loc("RetryingRMArtifactCleanUp", artifactsWorkingFolder, ex));
                Trace.Error(ex);

                return(true);
            };

            retryExecutor.Execute(
                () =>
            {
                executionContext.Output(StringUtil.Loc("RMCleaningArtifactsDirectory", artifactsWorkingFolder));

                try
                {
                    if (Directory.Exists(artifactsWorkingFolder))
                    {
                        IOUtil.DeleteDirectory(artifactsWorkingFolder, executionContext.CancellationToken);
                    }

                    Directory.CreateDirectory(artifactsWorkingFolder);
                }
                catch (Exception ex) when(ex is DirectoryNotFoundException || ex is UnauthorizedAccessException)
                {
                    throw new ArtifactCleanupFailedException(StringUtil.Loc("FailedCleaningupRMArtifactDirectory", artifactsWorkingFolder), ex);
                }
            });

            executionContext.Output(StringUtil.Loc("RMCleanedUpArtifactsDirectory", artifactsWorkingFolder));
        }