Beispiel #1
0
        private static void createUbuntuOSBuildScript(ProjectConfigInfo pcfi, string buildBranch)
        {
            string templateFilePath = Path.Combine(_buildScriptTemplateRootDir, pcfi.buildOS);
            string s = File.ReadAllText(templateFilePath);

            s = s.Replace("PROJECT_DIR={PROJECT_DIR}", "PROJECT_DIR=" + pcfi.projectName);
            s = s.Replace("HOST_SHARE_DIR_NAME={HOST_SHARE_DIR_NAME}", "HOST_SHARE_DIR_NAME=" + "/media/sf_" + Path.GetFileName(_ps.localSharedDir));
            s = s.Replace("GIT_AUTH_USER={GIT_AUTH_USER}", "GIT_AUTH_USER="******"GIT_AUTH_PASSWORD={GIT_AUTH_PASSWORD}", "GIT_AUTH_PASSWORD="******"GIT_PROTOCOL={GIT_PROTOCOL}", "GIT_PROTOCOL=" + pcfi.gitProtocol);
            s = s.Replace("GIT_REPO_URL={GIT_REPO_URL}", "GIT_REPO_URL=" + pcfi.gitUrl);
            s = s.Replace("BUILD_USER={BUILD_USER}", "BUILD_USER="******"BUILD_GROUP={BUILD_GROUP}", "BUILD_GROUP=" + pcfi.buildGroup);
            s = s.Replace("LOG_LINE_SEPARATOR={LOG_LINE_SEPARATOR}", "LOG_LINE_SEPARATOR=" + _lineSeparatorString);
            s = s.Replace("LOG_ELEM_SEPARATOR={LOG_ELEM_SEPARATOR}", "LOG_ELEM_SEPARATOR=" + _elemSeparatorString);
            s = s.Replace("BUILD_TRUNK={BUILD_TRUNK}", "BUILD_TRUNK=" + pcfi.buildTrunk);
            s = s.Replace("BUILD_BRANCH={BUILD_BRANCH}", "BUILD_BRANCH=" + buildBranch);
            s = s.Replace("BUILD_SH={BUILD_SH}", "BUILD_SH=" + pcfi.buildSH);
            s = s.Replace("BUILD_LOG_FILE={BUILD_LOG_FILE}", "BUILD_LOG_FILE=" + _buildLogFileName);
            s = s.Replace("BUILD_RESULT_FILE={BUILD_RESULT_FILE}", "BUILD_RESULT_FILE=" + _buildResultFileName);
            s = s.Replace("GIT_LOG_FILE={GIT_LOG_FILE}", "GIT_LOG_FILE=" + _gitLogFileName);
            s = s.Replace("BUILD_SCRIPT_LOG_FILE={BUILD_SCRIPT_LOG_FILE}", "BUILD_SCRIPT_LOG_FILE=" + _buildScriptLogFileName);
            s = s.Replace("VM_EXEC_STATUS_FILE={VM_EXEC_STATUS_FILE}", "VM_EXEC_STATUS_FILE=" + _vmExecStatusFileName);
            s = s.Replace("VM_GET_BUILD_LOG_BACKUP_FILE_NAME={VM_GET_BUILD_LOG_BACKUP_FILE_NAME}", "VM_GET_BUILD_LOG_BACKUP_FILE_NAME=" + _vmGetBuildLogBackupFileName);
            s = s.Replace("VM_EXEC_STATUS_ONGOING={VM_EXEC_STATUS_ONGOING}", "VM_EXEC_STATUS_ONGOING=" + _vmExecStatusOngoing);
            s = s.Replace("VM_EXEC_STATUS_FINISHED={VM_EXEC_STATUS_FINISHED}", "VM_EXEC_STATUS_FINISHED=" + _vmExecStatusFinished);
            s = s.Replace("VM_EXEC_STATUS_BEGIN_GIT_UPDATE_CODE={VM_EXEC_STATUS_BEGIN_GIT_UPDATE_CODE}", "VM_EXEC_STATUS_BEGIN_GIT_UPDATE_CODE=" + _vmExecStatusBeginGitUpdateCode);
            s = s.Replace("VM_EXEC_STATUS_FINISH_GIT_UPDATE_CODE={VM_EXEC_STATUS_FINISH_GIT_UPDATE_CODE}", "VM_EXEC_STATUS_FINISH_GIT_UPDATE_CODE=" + _vmExecStatusFinishGitUpdateCode);
            s = s.Replace("VM_EXEC_STATUS_BEGIN_BUILD_CODE={VM_EXEC_STATUS_BEGIN_BUILD_CODE}", "VM_EXEC_STATUS_BEGIN_BUILD_CODE=" + _vmExecStatusBeginBuildCode);
            s = s.Replace("VM_EXEC_STATUS_FINISH_BUILD_CODE={VM_EXEC_STATUS_FINISH_BUILD_CODE}", "VM_EXEC_STATUS_FINISH_BUILD_CODE=" + _vmExecStatusFinishBuildCode);
            s = s.Replace("VM_EXEC_STATUS_BEGIN_PACKAGE_FILES={VM_EXEC_STATUS_BEGIN_PACKAGE_FILES}", "VM_EXEC_STATUS_BEGIN_PACKAGE_FILES=" + _vmExecStatusBeginPackageFiles);
            s = s.Replace("VM_EXEC_STATUS_FINISH_PACKAGE_FILES={VM_EXEC_STATUS_FINISH_PACKAGE_FILES}", "VM_EXEC_STATUS_FINISH_PACKAGE_FILES=" + _vmExecStatusFinishPackageFiles);
            s = s.Replace("TASKS_INTERVAL_SECONDS={TASKS_INTERVAL_SECONDS}", "TASKS_INTERVAL_SECONDS=" + _tasksIntervalSeconds);
            s = s.Replace("BUILD_SUCCESS_MESSAGE={BUILD_SUCCESS_MESSAGE}", "BUILD_SUCCESS_MESSAGE=\"" + _buildSuccessMessage + "\"");
            s = s.Replace("BUILD_ERROR_MESSAGE={BUILD_ERROR_MESSAGE}", "BUILD_ERROR_MESSAGE=\"" + _buildErrorMessage + "\"");
            s = s.Replace("BUILD_NO_BUILD_FILE_MESSAGE={BUILD_NO_BUILD_FILE_MESSAGE}", "BUILD_NO_BUILD_FILE_MESSAGE=\"" + _buildNoBuildFileMessage + "\"");
            s = s.Replace("BUILD_RESULT_MESSAGE={BUILD_RESULT_MESSAGE}", "BUILD_RESULT_MESSAGE=\"" + _buildResultMessage + "\"");
            s = s.Replace("UPDATE_GIT_CODE_ERROR_MESSAGE={UPDATE_GIT_CODE_ERROR_MESSAGE}", "UPDATE_GIT_CODE_ERROR_MESSAGE=\"" + _updateGitCodeErrorMessage + "\"");

            File.WriteAllText(_buildScriptFilePath, s);
        }
Beispiel #2
0
        static private void loadSettingsConf()
        {
            _buildServerRootDir           = Path.Combine(Directory.GetDirectoryRoot(AppDomain.CurrentDomain.BaseDirectory), "BuildServer");
            _configsDir                   = Path.Combine(_buildServerRootDir, @"Configs");
            _programSettingConfigFilePath = Path.Combine(_configsDir, @"Settings.conf");

            List <string>     lines             = System.IO.File.ReadLines(_programSettingConfigFilePath).ToList();
            List <string>     elemList          = new List <string>();
            ProjectConfigInfo projectConfigInfo = new ProjectConfigInfo();
            string            section           = string.Empty;
            string            buildResultJsonOutputFilePathRelativeToBuildServerDir = string.Empty;
            string            sectionProgramSettings = "[Program Settings]";
            string            sectionProjectSettings = "[Project]";
            string            notifyEmailsString     = string.Empty;

            foreach (string line in lines)
            {
                if (line.StartsWith("#"))
                {
                    continue;
                }

                if (line.Trim().ToUpper() == sectionProgramSettings.Trim().ToUpper())
                {
                    section = sectionProgramSettings;
                    continue;
                }
                else if (line.Trim().ToUpper() == sectionProjectSettings.Trim().ToUpper())
                {
                    section           = sectionProjectSettings;
                    projectConfigInfo = new ProjectConfigInfo();
                    continue;
                }


                if (section == sectionProgramSettings)
                {
                    elemList = line.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries).ToList();

                    if (elemList != null && elemList.Count == 2)
                    {
                        if (elemList[0].Trim() == "VIRTUAL_BOX_EXE_PATH")
                        {
                            _ps.virtualBoxExePath = elemList[1].Trim();
                        }
                        else if (elemList[0].Trim() == "RELEASE_PACKAGE_DIR_PATH")
                        {
                            _ps.releasePackageDirPath = elemList[1].Trim();
                        }
                        else if (elemList[0].Trim() == "VDI_ROOT_DIR")
                        {
                            _ps.vdiRootDirPath = elemList[1].Trim();
                        }
                        else if (elemList[0].Trim() == "LOCAL_SHARED_DIR")
                        {
                            _ps.localSharedDir = elemList[1].Trim();

                            if (_ps.localSharedDir.IndexOf(@":\") < 0)
                            {
                                _ps.localSharedDir = Path.Combine(_buildServerRootDir, _ps.localSharedDir);
                            }

                            if (!Directory.Exists(_ps.localSharedDir))
                            {
                                Directory.CreateDirectory(_ps.localSharedDir);
                            }
                        }
                        else if (elemList[0].Trim() == "BUILD_TRUNK")
                        {
                            _ps.buildTrunk = elemList[1].Trim();
                        }
                        else if (elemList[0].Trim() == "BUILD_RESULT_JSON_FILES_DIR_RELATIVE_TO_BUILD_SERVER_ROOT_DIR")
                        {
                            _ps.buildResultJsonFilesDirRelativeToBuildServerDir = elemList[1].Trim();
                        }
                        else if (elemList[0].Trim() == "BUILR_RESULT_OF_ALL_PROJECTS_JSON_FILE_NAME")
                        {
                            _ps.buildResultOfAllProjectsJsonFileName = elemList[1].Trim();
                        }
//                        else if (elemList[0].Trim() == "RELEASE_PACKAGES_DIR")
                        //_ps.releasePackageDir = elemList[1].Trim();
                        else if (elemList[0].Trim() == "NOTIFY_EMAIL_USER_NAME")
                        {
                            _ps.notifyEmailUserName = elemList[1].Trim();
                        }
                        else if (elemList[0].Trim() == "NOTIFY_EMAIL_USER_PASSWORD")
                        {
                            _ps.notifyEmailUserPassword = elemList[1].Trim();
                        }
                        else if (elemList[0].Trim() == "CC_EMAILS_LIST")
                        {
                            try
                            {
                                _ps.notifyCcEmailsList = elemList[1].Trim().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
                            }
                            catch (Exception ex)
                            {
                                _ps.notifyCcEmailsList = new List <string>();
                            }
                        }
                        else if (elemList[0].Trim() == "KEEP_MASTER_BRANCH_RELEASE_PACKAGES_COUNT")
                        {
                            try
                            {
                                _ps.keepMasterBranchReleasePackagesCount = Convert.ToInt32(elemList[1].Trim());
                            }
                            catch (Exception ex)
                            {
                                _ps.keepMasterBranchReleasePackagesCount = 1;
                            }
                        }
                        else if (elemList[0].Trim() == "VM_CPU_NUMBER_COUNT")
                        {
                            try
                            {
                                _ps.vmCpuCount = Convert.ToInt32(elemList[1].Trim());
                            }
                            catch (Exception ex)
                            {
                                _ps.vmCpuCount = 1;
                            }
                        }
                        else if (elemList[0].Trim() == "VM_RAM_SIZE_IN_MB")
                        {
                            try
                            {
                                _ps.vmRamSizeInMB = Convert.ToInt32(elemList[1].Trim());
                            }
                            catch (Exception ex)
                            {
                                _ps.vmRamSizeInMB = 1024 * 4;
                            }
                        }
                    }
                }
                else if (section == sectionProjectSettings)
                {
                    elemList = line.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries).ToList();

                    if (elemList != null && elemList.Count == 2)
                    {
                        if (elemList[0].Trim() == "PROJECT_NAME")
                        {
                            projectConfigInfo.projectName = elemList[1].Trim();
                        }
                        else if (elemList[0].Trim() == "VDI_NAME")
                        {
                            projectConfigInfo.vdiName     = elemList[1].Trim();
                            projectConfigInfo.vdiFilePath = Path.Combine(_ps.vdiRootDirPath, projectConfigInfo.vdiName);
                        }
                        else if (elemList[0].Trim() == "GIT_PROTOCOL")
                        {
                            projectConfigInfo.gitProtocol = elemList[1].Trim();
                        }
                        else if (elemList[0].Trim() == "GIT_REPO_URL")
                        {
                            projectConfigInfo.gitUrl = elemList[1].Trim();
                        }
                        else if (elemList[0].Trim() == "GIT_USER")
                        {
                            projectConfigInfo.gitUser = elemList[1].Trim();
                        }
                        else if (elemList[0].Trim() == "GIT_PASSWORD")
                        {
                            projectConfigInfo.gitPassword = elemList[1].Trim();
                        }
                        else if (elemList[0].Trim() == "BUILD_TRUNK")
                        {
                            projectConfigInfo.buildTrunk = elemList[1].Trim();
                        }
                        else if (elemList[0].Trim() == "BUILD_USER")
                        {
                            projectConfigInfo.buildUser = elemList[1].Trim();
                        }
                        else if (elemList[0].Trim() == "BUILD_GROUP")
                        {
                            projectConfigInfo.buildGroup = elemList[1].Trim();
                        }
                        else if (elemList[0].Trim() == "BUILD_SH")
                        {
                            projectConfigInfo.buildSH = elemList[1].Trim();
                        }

                        /*
                         * else if (elemList[0].Trim() == "NOTIFY_EMAILS")
                         * {
                         * notifyEmailsString = elemList[1].Trim();
                         * projectConfigInfo.notifyPeople = new List<string>();
                         *
                         * if (!string.IsNullOrEmpty(notifyEmailsString))
                         *  projectConfigInfo.notifyPeople = notifyEmailsString.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList();
                         *
                         * }
                         */
                        else if (elemList[0].Trim() == "BUILD_SCRIPT_TEMPLATE")
                        {
                            projectConfigInfo.buildOS = elemList[1].Trim();
                            _projectConfigInfoList.Add(projectConfigInfo);
                        }
                    }
                }
            }
        }