Ejemplo n.º 1
0
 protected void initializeTeeUtil(AgentTaskPluginExecutionContext executionContext, CancellationToken cancellationToken)
 {
     teeUtil = new TeeUtil(
         executionContext.Variables.GetValueOrDefault("Agent.HomeDirectory")?.Value,
         executionContext.Variables.GetValueOrDefault("Agent.TempDirectory")?.Value,
         AgentKnobs.TeePluginDownloadRetryCount.GetValue(executionContext).AsInt(),
         executionContext.Debug,
         cancellationToken
         );
 }
Ejemplo n.º 2
0
        private async Task DownloadArtifacts(IExecutionContext executionContext,
                                             IList <AgentArtifactDefinition> agentArtifactDefinitions, string artifactsWorkingFolder)
        {
            Trace.Entering();

            CreateArtifactsFolder(executionContext, artifactsWorkingFolder);

            executionContext.Output(StringUtil.Loc("RMDownloadingArtifact"));

            bool isTeeUsed = PlatformUtil.RunningOnLinux && agentArtifactDefinitions.Any(x =>
                                                                                         x.ArtifactType == AgentArtifactType.Tfvc);

            if (isTeeUsed)
            {
                teeUtil = new TeeUtil(
                    executionContext.GetVariableValueOrDefault("Agent.HomeDirectory"),
                    executionContext.GetVariableValueOrDefault("Agent.TempDirectory"),
                    AgentKnobs.TeePluginDownloadRetryCount.GetValue(executionContext).AsInt(),
                    executionContext.Debug,
                    executionContext.CancellationToken
                    );
                await teeUtil.DownloadTeeIfAbsent();
            }

            try
            {
                foreach (AgentArtifactDefinition agentArtifactDefinition in agentArtifactDefinitions)
                {
                    // We don't need to check if its old style artifact anymore. All the build data has been fixed and all the build artifact has Alias now.
                    ArgUtil.NotNullOrEmpty(agentArtifactDefinition.Alias, nameof(agentArtifactDefinition.Alias));

                    var extensionManager         = HostContext.GetService <IExtensionManager>();
                    IArtifactExtension extension =
                        (extensionManager.GetExtensions <IArtifactExtension>()).FirstOrDefault(x =>
                                                                                               agentArtifactDefinition.ArtifactType == x.ArtifactType);

                    if (extension == null)
                    {
                        throw new InvalidOperationException(StringUtil.Loc("RMArtifactTypeNotSupported",
                                                                           agentArtifactDefinition.ArtifactType));
                    }

                    Trace.Info($"Found artifact extension of type {extension.ArtifactType}");
                    executionContext.Output(StringUtil.Loc("RMStartArtifactsDownload"));
                    ArtifactDefinition artifactDefinition =
                        ConvertToArtifactDefinition(agentArtifactDefinition, executionContext, extension);
                    executionContext.Output(StringUtil.Loc("RMArtifactDownloadBegin", agentArtifactDefinition.Alias,
                                                           agentArtifactDefinition.ArtifactType));

                    // Get the local path where this artifact should be downloaded.
                    string downloadFolderPath = Path.GetFullPath(Path.Combine(artifactsWorkingFolder,
                                                                              agentArtifactDefinition.Alias ?? string.Empty));

                    // download the artifact to this path.
                    RetryExecutor retryExecutor = new RetryExecutor();
                    retryExecutor.ShouldRetryAction = (ex) =>
                    {
                        executionContext.Output(StringUtil.Loc("RMErrorDuringArtifactDownload", ex));

                        bool retry = true;
                        if (ex is ArtifactDownloadException)
                        {
                            retry = false;
                        }
                        else
                        {
                            executionContext.Output(StringUtil.Loc("RMRetryingArtifactDownload"));
                            Trace.Warning(ex.ToString());
                        }

                        return(retry);
                    };

                    await retryExecutor.ExecuteAsync(
                        async() =>
                    {
                        var releaseFileSystemManager = HostContext.GetService <IReleaseFileSystemManager>();
                        executionContext.Output(StringUtil.Loc("RMEnsureArtifactFolderExistsAndIsClean",
                                                               downloadFolderPath));
                        releaseFileSystemManager.EnsureEmptyDirectory(downloadFolderPath,
                                                                      executionContext.CancellationToken);

                        await extension.DownloadAsync(executionContext, artifactDefinition, downloadFolderPath);
                    });

                    executionContext.Output(StringUtil.Loc("RMArtifactDownloadFinished",
                                                           agentArtifactDefinition.Alias));
                }

                executionContext.Output(StringUtil.Loc("RMArtifactsDownloadFinished"));
            }
            finally
            {
                if (isTeeUsed && !AgentKnobs.DisableTeePluginRemoval.GetValue(executionContext).AsBoolean())
                {
                    teeUtil.DeleteTee();
                }
            }
        }