Пример #1
0
        public async Task Execute(string buildConfigId, string branch, bool simulate = false)
        {
            Log.InfoFormat("Delete Git Branch in Build Chain.");

            var buildConfig = await _client.BuildConfigs.GetByConfigurationId(buildConfigId);

            var buildChainId     = buildConfig.Parameters[ParameterName.BuildConfigChainId].Value;
            var buildConfigChain = new BuildConfigChain(_client.BuildConfigs, buildConfig);

            DeleteGitBranchesInBuildChain(buildConfigChain, buildChainId, branch, simulate);
        }
Пример #2
0
        protected override void Read( )
        {
            var          expander = new Expander();
            IBuildConfig cfg      = new BuildConfigChain(this, rawConfig);

            foreach (var key in rawConfig.Keys)
            {
                var expandedValue = expander.Expand(cfg, rawConfig[key]);
                this[key] = expandedValue;
            }
        }
Пример #3
0
        public async Task Execute(string buildConfigId, bool simulate = false)
        {
            Log.Info("Propagate version.");

            var buildConfig = await _client.BuildConfigs.GetByConfigurationId(buildConfigId);

            var majorVersion     = buildConfig.Parameters[ParameterName.MajorVersion].Value;
            var minorVersion     = buildConfig.Parameters[ParameterName.MinorVersion].Value;
            var buildConfigChain = new BuildConfigChain(_client.BuildConfigs, buildConfig);

            await PropagateVersion(buildConfigChain, majorVersion, minorVersion, simulate);
        }
Пример #4
0
        public async Task Execute(string buildConfigId)
        {
            var buildConfig = await _client.BuildConfigs.GetByConfigurationId(buildConfigId);

            Log.Info($"Show versions for build config tree of {buildConfig.Id}");

            var buildConfigChain = new BuildConfigChain(_client.BuildConfigs, buildConfig);

            foreach (var node in buildConfigChain.Nodes)
            {
                Log.Info($"{node.Value.Id}: {node.Value.Parameters["MajorVersion"]?.Value}.{node.Value.Parameters["MinorVersion"]?.Value}");
            }
        }
        private async Task DeleteClonedBuildChain(BuildConfigChain buildConfigChain, string buildChainId, bool simulate)
        {
            var buildConfigIdsToDelete = buildConfigChain.Nodes
                                         .Where(node => node.Value.Parameters[ParameterName.BuildConfigChainId].Value == buildChainId)
                                         .Select(n => n.Value.Id)
                                         .ToList();

            buildConfigIdsToDelete.Reverse(); //to start deletion from leafs

            foreach (var buildConfigId in buildConfigIdsToDelete)
            {
                Log.InfoFormat("Deleting buildConfigId: {0}", buildConfigId);
                if (!simulate)
                {
                    await _client.BuildConfigs.DeleteBuildConfig(buildConfigId);
                }
            }
        }
Пример #6
0
        private async Task PropagateVersion(BuildConfigChain buildConfigChain, string majorVersion, string minorVersion, bool simulate)
        {
            foreach (var node in buildConfigChain.Nodes)
            {
                Log.Info($"Setting {node.Value.Id} to version {majorVersion}.{minorVersion}");
                if (!simulate)
                {
                    //1st pass: set different, then in a project, value. Just to make parameter "own", see more: https://youtrack.jetbrains.com/issue/TW-42811
                    await _client.BuildConfigs.SetParameterValue(
                        l => l.WithId(node.Value.Id),
                        ParameterName.MajorVersion,
                        "Temporary value, different from the parent project value!"
                        );

                    //2ns pass: set real value.
                    await _client.BuildConfigs.SetParameterValue(
                        l => l.WithId(node.Value.Id),
                        ParameterName.MajorVersion,
                        majorVersion,
                        true
                        );

                    //1st pass: set different, then in a project, value. Just to make parameter "own", see more: https://youtrack.jetbrains.com/issue/TW-42811
                    await _client.BuildConfigs.SetParameterValue(
                        l => l.WithId(node.Value.Id),
                        ParameterName.MinorVersion,
                        "Temporary value, different from the parent project value!"
                        );

                    //2ns pass: set real value.
                    await _client.BuildConfigs.SetParameterValue(
                        l => l.WithId(node.Value.Id),
                        ParameterName.MinorVersion,
                        minorVersion,
                        true
                        );
                }
            }
        }
Пример #7
0
        private void DeleteGitBranchesInBuildChain(BuildConfigChain buildConfigChain, string buildChainId, string branch, bool simulate)
        {
            var gitLabClient = _gitLabClientFactory.GetGitLabClient();

            var buildConfigsInChain = buildConfigChain.Nodes
                                      .Where(node => node.Value.Parameters[ParameterName.BuildConfigChainId].Value == buildChainId)
                                      .Select(n => n.Value)
                                      .ToList();

            foreach (var buildConfig in buildConfigsInChain)
            {
                Log.InfoFormat("Processing BuildConfigId {0}", buildConfig.Id);

                var gitRepoPath = buildConfig.Parameters[ParameterName.GitRepoPath].Value;

                if (string.IsNullOrWhiteSpace(gitRepoPath))
                {
                    Log.WarnFormat("    {0} parameter is empty. Skipping...", ParameterName.GitRepoPath);
                    continue;
                }

                gitRepoPath = gitRepoPath.Replace("%system.teamcity.projectName%", buildConfig.Project.Name);

                Project project;
                try
                {
                    project = gitLabClient.Projects.Get(gitRepoPath);
                }
                catch (System.Exception)
                {
                    Log.WarnFormat("    Gitlab project {0} is not found. Skipping...", gitRepoPath);
                    continue;
                }

                IRepositoryClient repo;
                try
                {
                    repo = gitLabClient.GetRepository(project.Id);
                }
                catch (System.Exception)
                {
                    Log.WarnFormat("    repo for project id {0} is not found. Skipping...", project.Id);
                    continue;
                }

                Branch existingBranch;

                try
                {
                    existingBranch = repo.Branches.Get(branch);
                }
                catch (System.Exception)
                {
                    Log.WarnFormat("    branch {0} in the project {1} does not exist. Nothing to delete. Skipping...", branch, gitRepoPath);
                    continue;
                }

                if (simulate)
                {
                    Log.InfoFormat("    simulating deletion of {0} branch in the {1} repo", branch, gitRepoPath);
                }
                else
                {
                    var branchRemovalStatus = repo.Branches.Delete(branch);

                    if (branchRemovalStatus.Succeed)
                    {
                        Log.InfoFormat("    deleted {0} branch in the {1} repo", branch, gitRepoPath);
                    }
                    else
                    {
                        Log.ErrorFormat("    failed to delete {0} branch in the {1} repo", branch, gitRepoPath);
                    }
                }
            }
        }