Exemplo n.º 1
0
        public TrackingConfig(
            IExecutionContext executionContext,
            IList <RepositoryResource> repositories,
            int buildDirectory)
            : this()
        {
            ArgUtil.NotNull(executionContext, nameof(executionContext));
            ArgUtil.NotNull(repositories, nameof(repositories));

            // Get the repo that we are going to checkout first to create the tracking info from.
            var primaryRepository = RepositoryUtil.GetPrimaryRepository(repositories);

            // Set the directories.
            BuildDirectory       = buildDirectory.ToString(CultureInfo.InvariantCulture);
            ArtifactsDirectory   = Path.Combine(BuildDirectory, Constants.Build.Path.ArtifactsDirectory);
            SourcesDirectory     = Path.Combine(BuildDirectory, Constants.Build.Path.SourcesDirectory);
            TestResultsDirectory = Path.Combine(BuildDirectory, Constants.Build.Path.TestResultsDirectory);

            // Set the other properties.
            CollectionId   = executionContext.Variables.System_CollectionId;
            DefinitionId   = executionContext.Variables.System_DefinitionId;
            RepositoryUrl  = primaryRepository?.Url.AbsoluteUri;
            RepositoryType = primaryRepository?.Type;
            System         = BuildSystem;
            UpdateJobRunProperties(executionContext);

            foreach (var repo in repositories)
            {
                RepositoryTrackingInfo.Add(new Build.RepositoryTrackingInfo(repo, SourcesDirectory));
            }

            // Now that we have all the repositories set up, we can compute the config hash
            HashKey = TrackingConfigHashAlgorithm.ComputeHash(CollectionId, DefinitionId, RepositoryTrackingInfo);
        }
        private string ComputeHash(
            IExecutionContext executionContext,
            IList <RepositoryTrackingInfo> repositories)
        {
            ArgUtil.NotNull(executionContext, nameof(executionContext));
            ArgUtil.ListNotNullOrEmpty(repositories, nameof(repositories));

            Trace.Verbose("Calculating pipeline workspace hash.");
            var    collectionId = executionContext.Variables.Get(Constants.Variables.System.CollectionId);
            var    definitionId = executionContext.Variables.Get(Constants.Variables.System.DefinitionId);
            string hash         = TrackingConfigHashAlgorithm.ComputeHash(collectionId, definitionId, repositories);

            Trace.Verbose($"Hash: {hash}");
            return(hash);
        }