Exemple #1
0
            internal PrebuildConfig(BuildInfo b, IniParser.Model.SectionData data)
            {
                /*
                 * _clone = new CmdConfig(b, data, "Clone");
                 * _checkout = new CmdConfig(b, data, "Checkout");
                 * _fetch = new CmdConfig(b, data, "Fetch");
                 */

                _projectDir       = GetValue(data.Keys, "ProjectDir");
                _newRepoInit      = GetValue(data.Keys, "NewRepoInitCommand");
                _existingRepoInit = GetValue(data.Keys, "ExistingRepoInitCommand");
                _postPrepare      = GetValue(data.Keys, "PostPrepareCommand");
                var r = new[] {
                    new { key = "{project_dir}", val = "" },
                    new { key = "{build_id}", val = b.id.ToString() },
                    new { key = "{project_id}", val = b.project_id.ToString() },
                    new { key = "{project_name}", val = Regex.Replace(b.project_name, @"\s+", "") },
                    new { key = "{commit}", val = b.sha },
                    new { key = "{previous_commit}", val = b.before_sha },
                    new { key = "{repo_url}", val = b.repo_url },
                    new { key = "{ref_name}", val = b.ref_name }
                };

                foreach (var rule in r)
                {
                    _projectDir = _projectDir.Replace(rule.key, rule.val);
                }

                r[0] = new { key = "{project_dir}", val = _projectDir };
                foreach (var rule in r)
                {
                    _newRepoInit      = _newRepoInit.Replace(rule.key, rule.val);
                    _existingRepoInit = _existingRepoInit.Replace(rule.key, rule.val);
                    _postPrepare      = _postPrepare.Replace(rule.key, rule.val);
                }
            }
Exemple #2
0
        public static PrebuildConfig getDataForBuild(gitlab_ci_runner.api.BuildInfo b)
        {
            if (!isConfigured())
            {
                throw new NotImplementedException("Situation when no configuration file is provided is not supported yet. Make sure that runner.cfg exists at the file location.");
            }
            IniParser.FileIniDataParser ini  = new IniParser.FileIniDataParser();
            IniParser.Model.IniData     data = ini.ReadFile(confPath);

            IniParser.Model.SectionData section = null;
            foreach (var sect in data.Sections)
            {
                string[] projectIdentifiers = sect.SectionName.Split(new char[] { '|' });
                foreach (var p in projectIdentifiers)
                {
                    string[] components = p.Split(new char[] { '=' });
                    if (components.Length == 2)
                    {
                        switch (components[0])
                        {
                        case "id":
                            if (Convert.ToInt32(components[1]) == b.project_id)
                            {
                                section = sect;
                            }
                            break;

                        case "name":
                            if (components[1] == b.project_name || components[1] == Regex.Replace(b.project_name, @"\s+", ""))
                            {
                                section = sect;
                            }
                            break;

                        default:
                            throw new Exception(String.Format("Cannot parse the {0} due to unknown project filter {1}", confPath, p));
                        }
                    }
                    else
                    {
                        if (p == "*")
                        {
                            section = sect;
                        }
                        else
                        {
                            if (p != "main")
                            {
                                throw new Exception(String.Format("Cannot parse the {0} while searching for the project prebuild steps commands. Section {1} cannot be recognized.", confPath, p));
                            }
                        }
                    }
                    if (section != null)
                    {
                        break;
                    }
                }
                if (section != null)
                {
                    break;
                }
            }
            return(new PrebuildConfig(b, section));
        }