Пример #1
0
 /// <summary>
 /// The main execution method for TFS Deployer it is this
 /// method that does all the work
 /// </summary>
 /// <param name="statusChanged"></param>
 public void ExecuteDeploymentProcess(BuildStatusChangeEvent statusChanged)
 {
     try
     {
         TraceHelper.TraceInformation(TraceSwitches.TfsDeployer, "Build Status Changed: Team Project {0}  Team Build Version: {1} From {2} : {3}",
                                      statusChanged.TeamProject, statusChanged.Id, statusChanged.StatusChange.OldValue, statusChanged.StatusChange.NewValue);
         var info = new BuildInformation(GetBuildDetail(statusChanged));
         DeploymentMappings mappings = ConfigurationReader.Read(statusChanged.TeamProject, info.Data);
         if (mappings != null)
         {
             foreach (Mapping mapping in mappings.Mappings)
             {
                 TraceHelper.TraceInformation(TraceSwitches.TfsDeployer, "Processing Mapping: Computer:{0}, Script:{1}", mapping.Computer, mapping.Script);
                 if (IsInterestedStatusChange(statusChanged, mapping, statusChanged.StatusChange))
                 {
                     IRunner runner = DetermineRunner(mapping);
                     runner.Execute(ConfigurationReader.WorkingDirectory, mapping, info);
                     ApplyRetainBuild(mapping, runner, info.Detail);
                     Alerter.Alert(mapping, info.Data, runner);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         TraceHelper.TraceError(TraceSwitches.TfsDeployer, ex);
     }
 }
Пример #2
0
        public void MappingProcessor_should_record_mapped_event_for_applicable_mappings()
        {
            // Arrange
            const int eventId                       = 7;
            var       mappingEvaluator              = MockRepository.GenerateStub <IMappingEvaluator>();
            var       deploymentEventRecorder       = MockRepository.GenerateStub <IDeploymentEventRecorder>();
            var       mappingExecutor               = MockRepository.GenerateStub <IMappingExecutor>();
            Func <IMappingExecutor> executorFactory = () => mappingExecutor;

            var mappingProcessor = new MappingProcessor(mappingEvaluator, deploymentEventRecorder, executorFactory);
            var postDeployAction = MockRepository.GenerateStub <IPostDeployAction>();

            var buildDetail = new BuildDetail();

            var mappings = new[] { new Mapping {
                                       Script = "AScript.ps1", Queue = "AQueue"
                                   } };

            mappingEvaluator.Stub(o => o.DoesMappingApply(null, null, null))
            .IgnoreArguments()
            .Return(true);

            var statusChanged = new BuildStatusChangeEvent {
                StatusChange = new Change()
            };

            // Act
            mappingProcessor.ProcessMappings(mappings, statusChanged, buildDetail, postDeployAction, eventId);

            // Assert
            deploymentEventRecorder.AssertWasCalled(o => o.RecordQueued(eventId, mappings[0].Script, mappings[0].Queue));
        }
Пример #3
0
        private void ProcessMapping(BuildStatusChangeEvent statusChanged, BuildDetail buildDetail, Mapping mapping, IPostDeployAction postDeployAction)
        {
            lock (GetLockObject(mapping))
            {
                var deployAgent = _deployAgentProvider.GetDeployAgent(mapping);

                // default to "happy; did nothing" if there's no deployment agent.
                var deployResult = new DeployAgentResult {
                    HasErrors = false, Output = string.Empty
                };

                if (deployAgent != null)
                {
                    using (var workingDirectory = new WorkingDirectory())
                    {
                        var deployAgentDataFactory = new DeployAgentDataFactory();
                        var deployData             = deployAgentDataFactory.Create(workingDirectory.DirectoryInfo.FullName,
                                                                                   mapping, buildDetail, statusChanged);

                        _deploymentFolderSource.DownloadDeploymentFolder(deployData.TfsBuildDetail, workingDirectory.DirectoryInfo.FullName);
                        deployResult = deployAgent.Deploy(deployData);
                    }
                }

                postDeployAction.DeploymentFinished(mapping, deployResult);
            }
        }
Пример #4
0
        public void Execute(BuildStatusChangeEvent statusChanged, BuildDetail buildDetail, Mapping mapping, IPostDeployAction postDeployAction, int deploymentId)
        {
            lock (_namedLockSet.GetLockObject(mapping.Queue))
            {
                _deploymentEventRecorder.RecordStarted(deploymentId);

                var deployAgent = _deployAgentProvider.GetDeployAgent(mapping);

                // default to "happy; did nothing" if there's no deployment agent.
                var deployResult = new DeployAgentResult {
                    HasErrors = false, Output = string.Empty
                };

                if (deployAgent != null)
                {
                    using (var workingDirectory = new WorkingDirectory())
                    {
                        var deployAgentDataFactory = new DeployAgentDataFactory();
                        var deployData             = deployAgentDataFactory.Create(workingDirectory.DirectoryInfo.FullName,
                                                                                   mapping, buildDetail, statusChanged);
                        deployData.DeploymentId = deploymentId;

                        _deploymentFolderSource.DownloadDeploymentFolder(deployData.TfsBuildDetail, workingDirectory.DirectoryInfo.FullName);
                        deployResult = deployAgent.Deploy(deployData);
                    }
                }

                postDeployAction.DeploymentFinished(mapping, deployResult);

                _deploymentEventRecorder.RecordFinished(deploymentId, deployResult.HasErrors, deployResult.Output);
            }
        }
Пример #5
0
        public void ExecuteDeploymentProcess(BuildStatusChangeEvent statusChanged)
        {
            try
            {
                TraceHelper.TraceInformation(TraceSwitches.TfsDeployer,
                                             "Build Status Changed: Team Project {0}  Team Build Version: {1} From {2} : {3}",
                                             statusChanged.TeamProject,
                                             statusChanged.Id,
                                             statusChanged.StatusChange.OldValue,
                                             statusChanged.StatusChange.NewValue);

                var tfsBuildDetail = GetBuildDetail(statusChanged);
                var buildDetail    = Mapper.Map <IBuildDetail, BuildDetail>(tfsBuildDetail);

                var postDeployAction = new PostDeployAction(buildDetail, tfsBuildDetail, _alerter);

                var mappings = _configurationReader.ReadMappings(buildDetail);

                _mappingProcessor.ProcessMappings(mappings, statusChanged, buildDetail, postDeployAction);
            }
            catch (Exception ex)
            {
                TraceHelper.TraceError(TraceSwitches.TfsDeployer, ex);
            }
        }
Пример #6
0
        private IBuildDetail GetBuildDetail(BuildStatusChangeEvent statusChanged)
        {
            var buildSpec = _buildServer.CreateBuildDefinitionSpec(statusChanged.TeamProject);
            var detail    = _buildServer.GetBuild(buildSpec, statusChanged.Id, null, QueryOptions.All);

            return(detail);
        }
Пример #7
0
        public void MappingExecutor_should_record_started_time()
        {
            // Arrange
            const int eventId                = 7;
            const int deploymentId           = 23;
            var       deployAgentProvider    = MockRepository.GenerateStub <IDeployAgentProvider>();
            var       deploymentFolderSource = MockRepository.GenerateStub <IDeploymentFolderSource>();

            var mapping = new Mapping();

            var deploymentEventRecorder = MockRepository.GenerateStub <IDeploymentEventRecorder>();

            deploymentEventRecorder.Stub(o => o.RecordQueued(eventId, mapping.Script, mapping.Queue))
            .Return(deploymentId);

            var namedLockSet = new NamedLockSet();

            var postDeployAction = MockRepository.GenerateStub <IPostDeployAction>();
            var buildDetail      = new BuildDetail();
            var statusChanged    = new BuildStatusChangeEvent {
                StatusChange = new Change()
            };

            var mappingExecutor = new MappingExecutor(deploymentEventRecorder, deployAgentProvider, deploymentFolderSource, namedLockSet);

            // Act
            mappingExecutor.Execute(statusChanged, buildDetail, mapping, postDeployAction, deploymentId);

            // Assert
            deploymentEventRecorder.AssertWasCalled(o => o.RecordStarted(deploymentId));
        }
Пример #8
0
        public void MappingProcessor_should_call_post_deploy_action_when_script_not_specified()
        {
            // Arrange
            var deployAgentProvider    = new DeployAgentProvider();
            var deploymentFolderSource = MockRepository.GenerateStub <IDeploymentFolderSource>();
            var mappingEvaluator       = MockRepository.GenerateStub <IMappingEvaluator>();
            var mappingProcessor       = new MappingProcessor(deployAgentProvider, deploymentFolderSource, mappingEvaluator);
            var postDeployAction       = MockRepository.GenerateStub <IPostDeployAction>();

            var buildDetail = new BuildDetail();

            var mappings = new[] { new Mapping {
                                       RetainBuildSpecified = true, RetainBuild = true
                                   } };

            mappingEvaluator.Stub(o => o.DoesMappingApply(null, null, null))
            .IgnoreArguments()
            .Return(true);

            var statusChanged = new BuildStatusChangeEvent {
                StatusChange = new Change()
            };

            // Act
            mappingProcessor.ProcessMappings(mappings, statusChanged, buildDetail, postDeployAction);

            // Assert
            postDeployAction.AssertWasCalled(o => o.DeploymentFinished(
                                                 Arg <Mapping> .Is.Equal(mappings[0]),
                                                 Arg <DeployAgentResult> .Matches(result => !result.HasErrors))
                                             );
        }
Пример #9
0
        public void LocalPowerShellDeployAgent_should_marshal_build_detail_across_AppDomains()
        {
            // Arrange
            var deploymentEventRecorder = MockRepository.GenerateStub <IDeploymentEventRecorder>();

            DeployAgentResult result;

            using (var scriptFile = new TemporaryFile(".ps1", "$TfsDeployerBuildDetail | Format-List"))
            {
                var buildDetail = new BuildDetail();

                var mapping = new Mapping
                {
                    NewQuality       = "Released",
                    OriginalQuality  = null,
                    ScriptParameters = new ScriptParameter[0],
                    Script           = scriptFile.FileInfo.Name
                };

                var buildStatusChangeEvent = new BuildStatusChangeEvent {
                    StatusChange = new Change()
                };

                var testDeployData = (new DeployAgentDataFactory()).Create(scriptFile.FileInfo.DirectoryName, mapping, buildDetail, buildStatusChangeEvent);

                var agent = new LocalPowerShellDeployAgent(deploymentEventRecorder);

                // Act
                result = agent.Deploy(testDeployData);
            }

            // Assert
            Assert.IsFalse(result.HasErrors, "Test script failed.");
        }
Пример #10
0
        public void Deployer_should_pass_build_status_to_mapping_processor()
        {
            // Arrange
            BuildDetail buildDetail = null;

            var statusChanged = new BuildStatusChangeEvent {
                StatusChange = new Change()
            };
            var reader = MockRepository.GenerateStub <IConfigurationReader>();

            var tfsBuildDetail = new StubBuildDetail {
                Status = Microsoft.TeamFoundation.Build.Client.BuildStatus.PartiallySucceeded
            };
            var buildServer = MockRepository.GenerateStub <IBuildServer>();

            buildServer.Stub(o => o.GetBuild(null, null, null, QueryOptions.None))
            .IgnoreArguments()
            .Return(tfsBuildDetail);

            var mappingProcessor = MockRepository.GenerateStub <IMappingProcessor>();

            mappingProcessor.Stub(o => o.ProcessMappings(null, null, null, null, 0))
            .IgnoreArguments()
            .WhenCalled(m => buildDetail = (BuildDetail)m.Arguments[2]);

            Func <BuildDetail, IBuildDetail, IPostDeployAction> postDeployActionFactory = (a, b) => MockRepository.GenerateStub <IPostDeployAction>();

            var deployer = new Deployer(reader, buildServer, mappingProcessor, postDeployActionFactory);

            // Act
            deployer.ExecuteDeploymentProcess(statusChanged, 0);

            // Assert
            Assert.AreEqual(global::TfsDeployer.TeamFoundation.BuildStatus.PartiallySucceeded, buildDetail.Status);
        }
Пример #11
0
        public void OutOfProcessPowerShellDeployAgent_should_serialize_build_detail_across_processes()
        {
            DeployAgentResult result;

            using (var scriptFile = new TemporaryFile(".ps1", "'Description:' + $TfsDeployerBuildDetail.BuildDefinition.Process.Description"))
            {
                var buildDetail = new BuildDetail {
                    BuildDefinition = { Process = { Description = "My Process Template" } }
                };

                var mapping = new Mapping
                {
                    NewQuality       = "Released",
                    OriginalQuality  = null,
                    ScriptParameters = new ScriptParameter[0],
                    Script           = scriptFile.FileInfo.Name
                };

                var buildStatusChangeEvent = new BuildStatusChangeEvent {
                    StatusChange = new Change()
                };

                var testDeployData = (new DeployAgentDataFactory()).Create(scriptFile.FileInfo.DirectoryName, mapping, buildDetail, buildStatusChangeEvent);

                var agent = new OutOfProcessPowerShellDeployAgent(null, ClrVersion.Version2);

                // Act
                result = agent.Deploy(testDeployData);
            }

            // Assert
            StringAssert.Contains(result.Output, "Description:My Process Template");
        }
            public virtual void Setup()
            {
                _tfsListener = MockRepository.GenerateStub <ITfsListener>();

                // configure deployer
                var deployer = MockRepository.GenerateStub <IDeployer>();

                deployer.Stub(o => o.ExecuteDeploymentProcess(null, 0))
                .IgnoreArguments()
                .WhenCalled(mi => _deployerExecuteCount++)
                .Repeat.Any();

                _tfsListener.BuildStatusChangeEventReceived += null;
                _eventRaiser = _tfsListener.GetEventRaiser(mo => mo.BuildStatusChangeEventReceived += null);

                // we're using a real DuplicateEventDetector
                _duplicateEventDetector = new DuplicateEventDetector();

                _statusChanged = new BuildStatusChangeEvent {
                    StatusChange = new Change()
                };

                var deploymentEventRecorder = MockRepository.GenerateStub <IDeploymentEventRecorder>();

                _deployerExecuteCount = 0;

                _buildStatusTrigger = new TfsBuildStatusTrigger(_tfsListener, () => deployer, _duplicateEventDetector, deploymentEventRecorder);
                _buildStatusTrigger.Start();
            }
Пример #13
0
        public void ShouldRejectUnchangedQuality()
        {
            const string TestWildcard = "*";

            var changeEvent = new BuildStatusChangeEvent();

            var mapping = new Mapping
            {
                Computer        = Environment.MachineName,
                NewQuality      = "SomeNewQuality",
                PermittedUsers  = null,
                OriginalQuality = TestWildcard
            };

            changeEvent.StatusChange = new Change
            {
                NewValue = "SomeNewQuality",
                OldValue = "SomeNewQuality"
            };

            var mappingEvaluator = new MappingEvaluator();
            var result           = mappingEvaluator.DoesMappingApply(mapping, changeEvent, BuildStatus.Succeeded.ToString());

            Assert.IsFalse(result);
        }
Пример #14
0
        public void ShouldMatchOriginalQualityWhenNullInConfigButEmptyInTfs()
        {
            const string TestNewQuality = "Pass";

            var changeEvent = new BuildStatusChangeEvent();

            var mapping = new Mapping
            {
                Computer        = Environment.MachineName,
                NewQuality      = TestNewQuality,
                PermittedUsers  = null,
                OriginalQuality = null
            };

            changeEvent.StatusChange = new Change
            {
                NewValue = TestNewQuality,
                OldValue = string.Empty
            };

            var mappingEvaluator = new MappingEvaluator();
            var result           = mappingEvaluator.DoesMappingApply(mapping, changeEvent, BuildStatus.Succeeded.ToString());

            Assert.IsTrue(result);
        }
        public void DeployAgentDataFactory_should_expose_event_qualities()
        {
            const string oldQuality = "QA";
            const string newQuality = "Production";

            // Arrange
            var deployScriptRoot = Path.GetTempPath();
            var mapping          = new Mapping();
            var buildDetail      = new BuildDetail();
            var changeEvent      = new BuildStatusChangeEvent
            {
                StatusChange = new Change {
                    OldValue = oldQuality, NewValue = newQuality
                }
            };

            var factory = new DeployAgentDataFactory();

            // Act
            var data = factory.Create(deployScriptRoot, mapping, buildDetail, changeEvent);

            // Assert
            Assert.AreEqual(oldQuality, data.OriginalQuality, "OriginalQuality");
            Assert.AreEqual(newQuality, data.NewQuality, "NewQuality");
        }
Пример #16
0
        public void ShouldMatchOriginalQualityWhenNullInConfigButEmptyInTfs()
        {
            const string TestNewQuality = "Pass";

            var changeEvent = new BuildStatusChangeEvent();

            var mapping = new Mapping()
            {
                Computer        = Environment.MachineName,
                NewQuality      = TestNewQuality,
                PermittedUsers  = null,
                OriginalQuality = null
            };

            var statusChange = new Change()
            {
                NewValue = TestNewQuality,
                OldValue = string.Empty
            };

            var deployer = new Deployer();
            var result   = deployer.IsInterestedStatusChange(changeEvent, mapping, statusChange);

            Assert.IsTrue(result, "IsInterestedStatusChange()");
        }
Пример #17
0
        public void MappingExecutor_should_call_post_deploy_action_when_script_not_specified()
        {
            // Arrange
            var deployAgentProvider     = MockRepository.GenerateStub <IDeployAgentProvider>();
            var deploymentFolderSource  = MockRepository.GenerateStub <IDeploymentFolderSource>();
            var deploymentEventRecorder = MockRepository.GenerateStub <IDeploymentEventRecorder>();
            var namedLockSet            = new NamedLockSet();
            var mappingExecutor         = new MappingExecutor(deploymentEventRecorder, deployAgentProvider, deploymentFolderSource, namedLockSet);
            var postDeployAction        = MockRepository.GenerateStub <IPostDeployAction>();

            var buildDetail = new BuildDetail();

            var mapping = new Mapping {
                RetainBuildSpecified = true, RetainBuild = true
            };

            var statusChanged = new BuildStatusChangeEvent {
                StatusChange = new Change()
            };

            // Act
            mappingExecutor.Execute(statusChanged, buildDetail, mapping, postDeployAction, 0);

            // Assert
            postDeployAction.AssertWasCalled(o => o.DeploymentFinished(
                                                 Arg <Mapping> .Is.Equal(mapping),
                                                 Arg <DeployAgentResult> .Matches(result => !result.HasErrors))
                                             );
        }
Пример #18
0
        public void Deployer_should_pass_build_definition_name_to_configuration_reader()
        {
            // Arrange
            BuildDetail buildDetail = null;

            var statusChanged = new BuildStatusChangeEvent {
                StatusChange = new Change()
            };
            var mappingProcessor = MockRepository.GenerateStub <IMappingProcessor>();

            var tfsBuildDetail = new StubBuildDetail {
                BuildDefinition = { Name = "foo" }
            };
            var buildServer = MockRepository.GenerateStub <IBuildServer>();

            buildServer.Stub(o => o.GetBuild(null, null, null, QueryOptions.None))
            .IgnoreArguments()
            .Return(tfsBuildDetail);

            var reader = MockRepository.GenerateStub <IConfigurationReader>();

            reader.Stub(o => o.ReadMappings(Arg <BuildDetail> .Is.Anything)).WhenCalled(m => buildDetail = (BuildDetail)m.Arguments[0]);

            Func <BuildDetail, IBuildDetail, IPostDeployAction> postDeployActionFactory = (a, b) => MockRepository.GenerateStub <IPostDeployAction>();

            var deployer = new Deployer(reader, buildServer, mappingProcessor, postDeployActionFactory);

            // Act
            deployer.ExecuteDeploymentProcess(statusChanged, 0);

            // Assert
            Assert.AreEqual("foo", buildDetail.BuildDefinition.Name);
        }
Пример #19
0
        public void ShouldMatchOriginalQualityOnWildcard()
        {
            const string TestWildcard = "*";

            var changeEvent = new BuildStatusChangeEvent();

            var mapping = new Mapping()
            {
                Computer        = Environment.MachineName,
                NewQuality      = "SomeNewQuality",
                PermittedUsers  = null,
                OriginalQuality = TestWildcard
            };

            var statusChange = new Change()
            {
                NewValue = "SomeNewQuality",
                OldValue = "DefinitelyNotTheWildCard"
            };

            var deployer = new Deployer();
            var result   = deployer.IsInterestedStatusChange(changeEvent, mapping, statusChange);

            Assert.IsTrue(result, "IsInterestedStatusChange()");
        }
Пример #20
0
        public bool IsInterestedStatusChange(BuildStatusChangeEvent changeEvent, Mapping mapping, Change statusChange)
        {
            bool isComputerMatch = string.Compare(Environment.MachineName, mapping.Computer, true) == 0;
            bool isOldValueMatch = string.Compare(mapping.OriginalQuality, statusChange.OldValue, true) == 0;
            bool isNewValueMatch = string.Compare(mapping.NewQuality, statusChange.NewValue) == 0;
            bool isUserPermitted = this.IsUserPermitted(changeEvent, mapping);

            return(isComputerMatch && isOldValueMatch && isNewValueMatch && isUserPermitted);
        }
 public void Setup()
 {
     _evaluator   = new MappingEvaluator();
     _mapping     = new MappingBuilder().Mapping;
     _changeEvent = new BuildStatusChangeEventBuilder
     {
         OriginalQuality = "BoringQuality",
         NewQuality      = "BoringQuality",
     }
     .BuildStatusChangeEvent;
 }
Пример #22
0
        public bool IsInterestedStatusChange(BuildStatusChangeEvent changeEvent, Mapping mapping, Change statusChange)
        {
            bool isComputerMatch = string.Compare(Environment.MachineName, mapping.Computer, true) == 0;

            string wildcardQuality = Properties.Settings.Default.BuildQualityWildcard;
            bool   isOldValueMatch = IsQualityMatch(statusChange.OldValue, mapping.OriginalQuality, wildcardQuality);
            bool   isNewValueMatch = IsQualityMatch(statusChange.NewValue, mapping.NewQuality, wildcardQuality);
            bool   isUserPermitted = IsUserPermitted(changeEvent, mapping);

            return(isComputerMatch && isOldValueMatch && isNewValueMatch && isUserPermitted);
        }
Пример #23
0
        private DeployAgentData CreateDeployAgentData()
        {
            var mapping   = CreateMapping();
            var buildInfo = CreateBuildDetail();
            var buildStatusChangeEvent = new BuildStatusChangeEvent {
                StatusChange = new Change()
            };
            var factory = new DeployAgentDataFactory();

            return(factory.Create(DeployScriptRoot, mapping, buildInfo, buildStatusChangeEvent));
        }
Пример #24
0
        private bool AreTooSimilar(BuildStatusChangeEvent a, BuildStatusChangeEvent b)
        {
            bool areTooSimilar = (a.ChangedBy == b.ChangedBy &&
                                  a.Id == b.Id &&
                                  a.StatusChange.FieldName == b.StatusChange.FieldName &&
                                  a.StatusChange.OldValue == b.StatusChange.OldValue &&
                                  a.StatusChange.NewValue == b.StatusChange.NewValue &&
                                  a.TeamProject == b.TeamProject &&
                                  a.Title == b.Title);

            return(areTooSimilar);
        }
Пример #25
0
        private void OnListenerBuildStatusChangeEventReceived(object sender, BuildStatusChangeEventArgs e)
        {
            BuildStatusChangeEvent changeEvent = e.EventRaised;

            if (_duplicateEventDetector.IsUnique(changeEvent))
            {
                var deployer = _deployerFactory.Create();
                ExecuteDeploymentProcessDelegate edpd = deployer.ExecuteDeploymentProcess;
                edpd.BeginInvoke(changeEvent, null, null);
            }
            else
            {
                TraceHelper.TraceWarning(TraceSwitches.TfsDeployer, "Received duplicate event '{0}' from TFS.", changeEvent.Title);
            }
        }
Пример #26
0
        public void ProcessMappings(IEnumerable <Mapping> mappings, BuildStatusChangeEvent statusChanged, BuildDetail buildDetail, IPostDeployAction postDeployAction)
        {
            var applicableMappings = from mapping in mappings
                                     where _mappingEvaluator.DoesMappingApply(mapping, statusChanged, buildDetail.Status.ToString())
                                     select mapping;

            foreach (var mapping in applicableMappings)
            {
                TraceHelper.TraceInformation(TraceSwitches.TfsDeployer,
                                             "Matching mapping found, executing, Computer:{0}, Script:{1}",
                                             mapping.Computer,
                                             mapping.Script);

                ((ProcessMappingDelegate)ProcessMapping).BeginInvoke(statusChanged, buildDetail, mapping, postDeployAction, null, null);
            }
        }
Пример #27
0
        private bool IsUserPermitted(BuildStatusChangeEvent changeEvent, Mapping mapping)
        {
            if (mapping.PermittedUsers == null)
            {
                return(true);
            }

            bool isUserPermitted;

            string[]      permittedUsers     = mapping.PermittedUsers.Split(';');
            List <string> permittedUsersList = new List <string>(permittedUsers);

            isUserPermitted = permittedUsersList.Exists(
                delegate(string value) { return(string.Compare(changeEvent.ChangedBy, value, true) == 0); }
                );
            return(isUserPermitted);
        }
 public BuildStatusChangeEventBuilder()
 {
     _event = new BuildStatusChangeEvent
     {
         TeamFoundationServerUrl = "https://tfs.example.com/tfs",
         TeamProject             = "Test Project",
         Title          = "Test Project Build Test_Project_20101024.2 Quality Changed To NewStatus",
         Id             = "Test_Project_20101024.2",
         Url            = "http://tfs.example.com/Build/Build.aspx",
         TimeZoneOffset = "+10:00:00",
         ChangedTime    = DateTime.Now.ToString(),
         ChangedBy      = "EXAMPLE\\CaramelloKoala",
         StatusChange   = new Change {
             OldValue = "OriginalQuality", NewValue = "NewQuality"
         },
     };
 }
Пример #29
0
        public void MappingExecutor_should_pass_deployment_id_to_deploy_agent_via_deploy_agent_data()
        {
            // Arrange
            const int deploymentId = 23;

            DeployAgentData deployData  = null;
            var             deployAgent = MockRepository.GenerateStub <IDeployAgent>();

            deployAgent.Stub(o => o.Deploy(null))
            .IgnoreArguments()
            .Return(new DeployAgentResult())
            .WhenCalled(o => deployData = (DeployAgentData)o.Arguments[0]);

            var deployAgentProvider = MockRepository.GenerateStub <IDeployAgentProvider>();

            deployAgentProvider.Stub(o => o.GetDeployAgent(null))
            .IgnoreArguments()
            .Return(deployAgent);

            var deploymentFolderSource = MockRepository.GenerateStub <IDeploymentFolderSource>();

            var mapping = new Mapping();

            var deploymentEventRecorder = MockRepository.GenerateStub <IDeploymentEventRecorder>();

            deploymentEventRecorder.Stub(o => o.RecordQueued(0, null, null))
            .IgnoreArguments()
            .Return(deploymentId);

            var namedLockSet = new NamedLockSet();

            var mappingExecutor  = new MappingExecutor(deploymentEventRecorder, deployAgentProvider, deploymentFolderSource, namedLockSet);
            var postDeployAction = MockRepository.GenerateStub <IPostDeployAction>();

            var buildDetail = new BuildDetail();

            var statusChanged = new BuildStatusChangeEvent {
                StatusChange = new Change()
            };

            // Act
            mappingExecutor.Execute(statusChanged, buildDetail, mapping, postDeployAction, deploymentId);

            // Assert
            Assert.AreEqual(deploymentId, deployData.DeploymentId);
        }
Пример #30
0
        public void ExecuteDeploymentProcess(BuildStatusChangeEvent statusChanged)
        {
            try
            {
                TraceHelper.TraceInformation(TraceSwitches.TfsDeployer,
                                             "Build Status Changed: Team Project {0}  Team Build Version: {1} From {2} : {3}",
                                             statusChanged.TeamProject,
                                             statusChanged.Id,
                                             statusChanged.StatusChange.OldValue,
                                             statusChanged.StatusChange.NewValue);

                var info = new BuildInformation(GetBuildDetail(statusChanged));
                using (var workingDirectory = new WorkingDirectory())
                {
                    var mappings = _configurationReader.ReadMappings(statusChanged.TeamProject, info.Data, workingDirectory);

                    foreach (var mapping in mappings)
                    {
                        TraceHelper.TraceInformation(TraceSwitches.TfsDeployer,
                                                     "Processing Mapping: Computer:{0}, Script:{1}",
                                                     mapping.Computer,
                                                     mapping.Script);

                        if (_mappingEvaluator.DoesMappingApply(mapping, statusChanged, info.Detail.Status.ToString()))
                        {
                            TraceHelper.TraceInformation(TraceSwitches.TfsDeployer,
                                                         "Matching mapping found, running script {0}",
                                                         mapping.Script);

                            var deployAgent = _deployAgentProvider.GetDeployAgent(mapping);

                            var deployData   = CreateDeployAgentData(workingDirectory.DirectoryInfo.FullName, mapping, info);
                            var deployResult = deployAgent.Deploy(deployData);

                            ApplyRetainBuild(mapping, deployResult, info.Detail);
                            _alerter.Alert(mapping, info.Data, deployResult);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                TraceHelper.TraceError(TraceSwitches.TfsDeployer, ex);
            }
        }