예제 #1
0
        public async Task Execute(long sourceBuildId, string newNameSuffix, bool simulate)
        {
            Log.InfoFormat("Deep Clone Build Config. sourceBuildId: {0}, newNameSuffix: {1}", sourceBuildId, newNameSuffix);

            var sourceBuild = await _client.Builds.ById(sourceBuildId);

            _buildConfigXmlClient.Simulate = simulate;

            _simulate          = simulate;
            _sourceBuildConfig = await _client.BuildConfigs.GetByConfigurationId(sourceBuild.BuildTypeId);

            _newNameSuffix = newNameSuffix;
            _newBranchName = VcsRootHelper.ToValidGitBranchName(_newNameSuffix);
            _buildChainId  = Guid.NewGuid().ToString();
            _buildChain    = new BuildChain(_client.Builds, sourceBuild);

            var buildConfigsToClone = await GetBuildsToClone();

            foreach (var b in buildConfigsToClone)
            {
                Log.Info($"==== Branch {b.HistoricBuild.BuildTypeId} from Build #{b.HistoricBuild.Number} (id: {b.HistoricBuild.Id}) ====");
                if (!_simulate)
                {
                    await _vcsRootHelper.BranchUsingGitLabApi(b.HistoricBuild.Id, _newBranchName);
                }
            }

            var cloneBuildConfigCommands = GetCloneBuildConfigsCommands(buildConfigsToClone.ToList());

            foreach (var c in cloneBuildConfigCommands)
            {
                Log.Info($"==== {c} ====");
                if (!_simulate)
                {
                    c.Execute();
                }
            }

            var swapDependencyCommands = GetSwapDependenciesCommands(buildConfigsToClone);

            foreach (var c in swapDependencyCommands)
            {
                Log.Info($"==== {c} ====");
                if (!_simulate)
                {
                    c.Execute();
                }
            }

            if (!_simulate)
            {
                _buildConfigXmlClient.Push();
            }
        }
예제 #2
0
            public void Should_deep_clone_build_config()
            {
                var teamCityClient                = CreateTeamCityClient();
                var gitRepositoryFactory          = CreateGitRepositoryFactory();
                var gitLabClientFactory           = CreateGitLabClientFactory();
                var buildConfigXmlClient          = new BuildConfigXmlClient(teamCityClient, gitRepositoryFactory);
                var vcsRootHelper                 = new VcsRootHelper(teamCityClient, gitRepositoryFactory, gitLabClientFactory);
                var deleteClonedBuildChainUseCase = new DeepCloneBuildConfigUseCase(teamCityClient, vcsRootHelper, buildConfigXmlClient);

                deleteClonedBuildChainUseCase.Execute(sourceBuildId: 522, simulate: false, newNameSuffix: "Deep Clone Test 8").Wait();
            }
예제 #3
0
            public void Should_clone_child_build_config()
            {
                var teamCityClient       = CreateTeamCityClient();
                var gitRepositoryFactory = CreateGitRepositoryFactory();
                var gitLabClientFactory  = CreateGitLabClientFactory();
                var buildConfigXmlClient = new BuildConfigXmlClient(teamCityClient, gitRepositoryFactory);
                var vcsRootHelper        = new VcsRootHelper(teamCityClient, gitRepositoryFactory, gitLabClientFactory);

                var cloneChildBuildConfigUseCase = new CloneChildBuildConfigUseCase(CreateTeamCityClient(), vcsRootHelper, buildConfigXmlClient);

                cloneChildBuildConfigUseCase.Execute("Installers_Sunlife_PaymentCollections_Trunk", "Installers_Sunlife_VitalObjectsSuite_trunkTestingDependenciesConfig12", false).Wait();
            }
예제 #4
0
            public void Should_clone_root_build_config()
            {
                var teamCityClient       = CreateTeamCityClient();
                var gitRepositoryFactory = CreateGitRepositoryFactory();
                var gitLabClientFactory  = CreateGitLabClientFactory();
                var buildConfigXmlClient = new BuildConfigXmlClient(teamCityClient, gitRepositoryFactory);
                var vcsRootHelper        = new VcsRootHelper(teamCityClient, gitRepositoryFactory, gitLabClientFactory);

                var cloneRootBuildConfigUseCase = new CloneRootBuildConfigUseCase(teamCityClient, buildConfigXmlClient, vcsRootHelper);

                cloneRootBuildConfigUseCase.Execute(781, "TestingDependenciesConfig12", false).Wait();
            }
        public async Task Execute(long sourceBuildId, string newNameSuffix, bool simulate)
        {
            Log.InfoFormat("Clone Root Build Config. sourceBuildId: {0}, newNameSuffix: {1}", sourceBuildId, newNameSuffix);

            var sourceBuild = await _client.Builds.ById(sourceBuildId);

            await EnsureUniqueSuffixProvided(sourceBuild, newNameSuffix);

            var newBranchName = VcsRootHelper.ToValidGitBranchName(newNameSuffix);

            Log.InfoFormat("==== Branch {2} from Build #{1} (id: {0}) ====", sourceBuild.Id, sourceBuild.Number, sourceBuild.BuildConfig.Id);
            if (!simulate)
            {
                await _vcsRootHelper.BranchUsingLocalGit(sourceBuildId, newBranchName);
            }

            Log.InfoFormat("==== Clone {2} from Build #{1} (id: {0}) ====", sourceBuild.Id, sourceBuild.Number, sourceBuild.BuildConfig.Id);
            if (!simulate)
            {
                await CopyBuildConfigurationFromBuild(sourceBuild, newNameSuffix, newBranchName);
            }
        }
        private async Task Init(string sourceBuildConfigId, string targetRootBuildConfigId, bool simulate)
        {
            _simulate          = simulate;
            _sourceBuildConfig = await _client.BuildConfigs.GetByConfigurationId(sourceBuildConfigId);

            _targetRootBuildConfig = await _client.BuildConfigs.GetByConfigurationId(targetRootBuildConfigId);

            if (_targetRootBuildConfig.Parameters[ParameterName.ClonedFromBuildId] == null)
            {
                throw new Exception(
                          $"Target root Build Config doesn't appear to be cloned. It is missing the \"{ParameterName.ClonedFromBuildId}\" parameter.");
            }

            _targetBuildChainId = _targetRootBuildConfig.Parameters[ParameterName.BuildConfigChainId].Value;
            _newNameSuffix      = _targetRootBuildConfig.Parameters[ParameterName.CloneNameSuffix].Value;
            _newBranchName      = VcsRootHelper.ToValidGitBranchName(_newNameSuffix);
            _dependencyChain    = new DependencyChain(_client, _targetRootBuildConfig);

            if (!_dependencyChain.Contains(_sourceBuildConfig.Id))
            {
                throw new Exception(
                          $"Cannot clone Build Config, because requested source Build Config ({_sourceBuildConfig.Id}) " +
                          $"is not found in the current Build Config chain for target Build Config ({targetRootBuildConfigId}). " +
                          $"Make sure target Build Config depends on source Build Config." + Environment.NewLine +
                          $"Currently discovered Build Config chain is: " + Environment.NewLine + "{_dependencyChain}");
            }

            if (_sourceBuildConfig.Parameters[ParameterName.BuildConfigChainId].Value == _targetBuildChainId)
            {
                throw new Exception(
                          $"It appears that Build Config \"{_sourceBuildConfig.Id}\" is already a cloned for target " +
                          $"Build Config \"{_targetRootBuildConfig.Id}\", because \"{ParameterName.BuildConfigChainId}\" " +
                          $"parameter is the same \"{_sourceBuildConfig.Parameters[ParameterName.BuildConfigChainId]}\" . " +
                          $"Create a new clone of root Build Config first");
            }
        }