public override async Task RunAsync(AgentTaskPluginExecutionContext executionContext, CancellationToken token) { var repoAlias = executionContext.TaskVariables.GetValueOrDefault("repository")?.Value; if (!string.IsNullOrEmpty(repoAlias)) { var repo = executionContext.Repositories.Single(x => string.Equals(x.Alias, repoAlias, StringComparison.OrdinalIgnoreCase)); ArgUtil.NotNull(repo, nameof(repo)); MergeCheckoutOptions(executionContext, repo); ISourceProvider sourceProvider = SourceProviderFactory.GetSourceProvider(repo.Type); await sourceProvider.PostJobCleanupAsync(executionContext, repo); } }
public override async Task RunAsync(AgentTaskPluginExecutionContext executionContext, CancellationToken token) { var sourceSkipVar = StringUtil.ConvertToBoolean(executionContext.Variables.GetValueOrDefault("agent.source.skip")?.Value) || !StringUtil.ConvertToBoolean(executionContext.Variables.GetValueOrDefault("build.syncSources")?.Value ?? bool.TrueString); if (sourceSkipVar) { executionContext.Output($"Skip sync source for repository."); return; } var repoAlias = executionContext.GetInput(Pipelines.PipelineConstants.CheckoutTaskInputs.Repository, true); var repo = executionContext.Repositories.Single(x => string.Equals(x.Alias, repoAlias, StringComparison.OrdinalIgnoreCase)); MergeCheckoutOptions(executionContext, repo); ISourceProvider sourceProvider = SourceProviderFactory.GetSourceProvider(repo.Type); await sourceProvider.GetSourceAsync(executionContext, repo, token); }
public override async Task RunAsync(AgentTaskPluginExecutionContext executionContext, CancellationToken token) { var repoAlias = executionContext.TaskVariables.GetValueOrDefault("repository")?.Value; if (!string.IsNullOrEmpty(repoAlias)) { var repo = executionContext.Repositories.Single(x => string.Equals(x.Alias, repoAlias, StringComparison.OrdinalIgnoreCase)); ArgUtil.NotNull(repo, nameof(repo)); MergeCheckoutOptions(executionContext, repo); ISourceProvider sourceProvider = SourceProviderFactory.GetSourceProvider(repo.Type); await sourceProvider.PostJobCleanupAsync(executionContext, repo); } if (!PlatformUtil.RunningOnWindows && !AgentKnobs.DisableTeePluginRemoval.GetValue(executionContext).AsBoolean()) { initializeTeeUtil(executionContext, token); teeUtil.DeleteTee(); } }
public override async Task RunAsync(AgentTaskPluginExecutionContext executionContext, CancellationToken token) { var sourceSkipVar = StringUtil.ConvertToBoolean(executionContext.Variables.GetValueOrDefault("agent.source.skip")?.Value) || !StringUtil.ConvertToBoolean(executionContext.Variables.GetValueOrDefault("build.syncSources")?.Value ?? bool.TrueString); if (sourceSkipVar) { executionContext.Output($"Skip sync source for repository."); return; } var repoAlias = executionContext.GetInput(Pipelines.PipelineConstants.CheckoutTaskInputs.Repository, true); var repo = executionContext.Repositories.Single(x => string.Equals(x.Alias, repoAlias, StringComparison.OrdinalIgnoreCase)); executionContext.PublishTelemetry(area: "AzurePipelinesAgent", feature: "Checkout", properties: new Dictionary <string, string> { { "RepoType", $"{repo.Type}" }, { "HostOS", $"{PlatformUtil.HostOS}" } }); MergeCheckoutOptions(executionContext, repo); var currentRepoPath = repo.Properties.Get <string>(Pipelines.RepositoryPropertyNames.Path); var buildDirectory = executionContext.Variables.GetValueOrDefault("agent.builddirectory")?.Value; var tempDirectory = executionContext.Variables.GetValueOrDefault("agent.tempdirectory")?.Value; ArgUtil.NotNullOrEmpty(currentRepoPath, nameof(currentRepoPath)); ArgUtil.NotNullOrEmpty(buildDirectory, nameof(buildDirectory)); ArgUtil.NotNullOrEmpty(tempDirectory, nameof(tempDirectory)); // Determine the path that we should clone/move the repository into const string sourcesDirectory = "s"; //Constants.Build.Path.SourcesDirectory string expectRepoPath; var path = executionContext.GetInput("path"); if (!string.IsNullOrEmpty(path)) { // When the checkout task provides a path, always use that one expectRepoPath = IOUtil.ResolvePath(buildDirectory, path); if (!expectRepoPath.StartsWith(buildDirectory.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar)) { throw new ArgumentException($"Input path '{path}' should resolve to a directory under '{buildDirectory}', current resolved path '{expectRepoPath}'."); } } else if (HasMultipleCheckouts(executionContext)) { // When there are multiple checkout tasks (and this one didn't set the path), default to directory 1/s/<repoName> expectRepoPath = Path.Combine(buildDirectory, sourcesDirectory, RepositoryUtil.GetCloneDirectory(repo)); } else { // When there's a single checkout task that doesn't have path set, default to sources directory 1/s expectRepoPath = Path.Combine(buildDirectory, sourcesDirectory); } // Update the repository path in the worker process executionContext.UpdateRepositoryPath(repoAlias, expectRepoPath); executionContext.Debug($"Repository requires to be placed at '{expectRepoPath}', current location is '{currentRepoPath}'"); if (!string.Equals(currentRepoPath.Trim(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar), expectRepoPath.Trim(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar), IOUtil.FilePathStringComparison)) { executionContext.Output($"Repository is current at '{currentRepoPath}', move to '{expectRepoPath}'."); var count = 1; var staging = Path.Combine(tempDirectory, $"_{count}"); while (Directory.Exists(staging)) { count++; staging = Path.Combine(tempDirectory, $"_{count}"); } try { executionContext.Debug($"Move existing repository '{currentRepoPath}' to '{expectRepoPath}' via staging directory '{staging}'."); IOUtil.MoveDirectory(currentRepoPath, expectRepoPath, staging, CancellationToken.None); } catch (Exception ex) { executionContext.Debug("Catch exception during repository move."); executionContext.Debug(ex.ToString()); executionContext.Warning("Unable move and reuse existing repository to required location."); IOUtil.DeleteDirectory(expectRepoPath, CancellationToken.None); } executionContext.Output($"Repository will be located at '{expectRepoPath}'."); repo.Properties.Set <string>(Pipelines.RepositoryPropertyNames.Path, expectRepoPath); } ISourceProvider sourceProvider = SourceProviderFactory.GetSourceProvider(repo.Type); await sourceProvider.GetSourceAsync(executionContext, repo, token); }
public override async Task RunAsync(AgentTaskPluginExecutionContext executionContext, CancellationToken token) { var sourceSkipVar = StringUtil.ConvertToBoolean(executionContext.Variables.GetValueOrDefault("agent.source.skip")?.Value) || !StringUtil.ConvertToBoolean(executionContext.Variables.GetValueOrDefault("build.syncSources")?.Value ?? bool.TrueString); if (sourceSkipVar) { executionContext.Output($"Skip sync source for repository."); return; } var repoAlias = executionContext.GetInput(Pipelines.PipelineConstants.CheckoutTaskInputs.Repository, true); var repo = executionContext.Repositories.Single(x => string.Equals(x.Alias, repoAlias, StringComparison.OrdinalIgnoreCase)); MergeCheckoutOptions(executionContext, repo); var currentRepoPath = repo.Properties.Get <string>(Pipelines.RepositoryPropertyNames.Path); var buildDirectory = executionContext.Variables.GetValueOrDefault("agent.builddirectory")?.Value; var tempDirectory = executionContext.Variables.GetValueOrDefault("agent.tempdirectory")?.Value; ArgUtil.NotNullOrEmpty(currentRepoPath, nameof(currentRepoPath)); ArgUtil.NotNullOrEmpty(buildDirectory, nameof(buildDirectory)); ArgUtil.NotNullOrEmpty(tempDirectory, nameof(tempDirectory)); string expectRepoPath; var path = executionContext.GetInput("path"); if (!string.IsNullOrEmpty(path)) { expectRepoPath = IOUtil.ResolvePath(buildDirectory, path); if (!expectRepoPath.StartsWith(buildDirectory.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar)) { throw new ArgumentException($"Input path '{path}' should resolve to a directory under '{buildDirectory}', current resolved path '{expectRepoPath}'."); } } else { // When repository doesn't has path set, default to sources directory 1/s expectRepoPath = Path.Combine(buildDirectory, "s"); } executionContext.UpdateRepositoryPath(repoAlias, expectRepoPath); executionContext.Debug($"Repository requires to be placed at '{expectRepoPath}', current location is '{currentRepoPath}'"); if (!string.Equals(currentRepoPath.Trim(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar), expectRepoPath.Trim(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar), IOUtil.FilePathStringComparison)) { executionContext.Output($"Repository is current at '{currentRepoPath}', move to '{expectRepoPath}'."); var count = 1; var staging = Path.Combine(tempDirectory, $"_{count}"); while (Directory.Exists(staging)) { count++; staging = Path.Combine(tempDirectory, $"_{count}"); } try { executionContext.Debug($"Move existing repository '{currentRepoPath}' to '{expectRepoPath}' via staging directory '{staging}'."); IOUtil.MoveDirectory(currentRepoPath, expectRepoPath, staging, CancellationToken.None); } catch (Exception ex) { executionContext.Debug("Catch exception during repository move."); executionContext.Debug(ex.ToString()); executionContext.Warning("Unable move and reuse existing repository to required location."); IOUtil.DeleteDirectory(expectRepoPath, CancellationToken.None); } executionContext.Output($"Repository will be located at '{expectRepoPath}'."); repo.Properties.Set <string>(Pipelines.RepositoryPropertyNames.Path, expectRepoPath); } ISourceProvider sourceProvider = SourceProviderFactory.GetSourceProvider(repo.Type); await sourceProvider.GetSourceAsync(executionContext, repo, token); }