/// <summary> /// 手动编译 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnBuild_Click(object sender, RoutedEventArgs e) { ProjectController projectController = new ProjectController(); if (respoPath.Text == "" || projectName.Text == "" || Workspace.Text == "" || Host.Text == "" || Mailto.Text == "" || Buildcomand.Text == "") { MessageBox.Show("请先填写完整的信息!"); } else { ProjectInfo projectInfo = new ProjectInfo(); projectInfo.WorkDirectory = Workspace.Text; projectInfo.RepositoryPath = respoPath.Text; projectInfo.MailTo = Mailto.Text; projectInfo.BuildCommand = Buildcomand.Text; string buildResult = ""; string time = ""; Task buildTask = new Task(() => { projectInfo.BuildTime = DateTime.Now.ToString(); log = projectController.Build(projectInfo.BuildCommand, projectInfo.WorkDirectory, out buildResult, out err, out time); Dictionary <string, string> setValue = new Dictionary <string, string>(); setValue.Add("Name", _svnController.GetLocalInfo(projectInfo).Author.Split('\\')[1]); if (buildResult == "successful") { _projectController.CommitStat("success", setValue, "config/Member", "../../../common/res/InfoStatics.xml"); } else if (buildResult == "failed") { _projectController.CommitStat("failure", setValue, "config/Member", "../../../common/res/InfoStatics.xml"); } Dispatcher.BeginInvoke(new Action(() => { duration = time; logs.Text = "编译信息" + log + "\n" + this.logs.Text + "\n"; lastRe.Text = buildResult; //检验是否存储信息(最近一次编译信息,以及后台存储信息) Dictionary <string, string> lastProject = new Dictionary <string, string>(); //修改存储最近完成项目信息的xml文件 lastProject.Add("projectName", projectName.Text); lastProject.Add("buildTime", projectInfo.BuildTime); lastProject.Add("duration", projectInfo.Duration); lastProject.Add("result", buildResult); projectController.ModifyProject(lastProject, null, "../../../common/res/LastestInfo.xml", "lastest"); })); }); buildTask.Start(); } }
/// <summary> /// 收到post信息,首先对分支进行切换,然后git pull拉取本分支的最新代码,最后再进行项目的编译工作 /// </summary> /// <param name="projectInfo">项目信息</param> /// <param name="pushBranch">操作的分支</param> /// <param name="CIConfigPath">项目config路径</param> /// <returns></returns> public ProjectInfo buildProject(ProjectInfo projectInfo, string pushBranch, string CIConfigPath) { //进行分支切换操作 bool switchBranch = _gitlabController.git_checkout("git checkout " + pushBranch, projectInfo.WorkDirectory); //若是分支切换成功,进行项目编译 if (switchBranch) { //获取gitlab信息 GitInfo gitlabInfo = _configController.GitInfoQuery("config/GitLabInfo", CIConfigPath); Boolean gitPullResult = _gitlabController.Libgit2_GitPull(projectInfo.WorkDirectory, gitlabInfo.Username, gitlabInfo.Password, gitlabInfo.Emailaddress); if (gitPullResult) { string buildResult; //存储编译是否成功 string error; //存储编译的日志文件 string log; //存储编译的所有信息 string time; ConfigInfo configInfo = _configController.ConfigQuery("config/preferences", CIConfigPath); projectInfo.BuildTime = DateTime.Now.ToString(); projectInfo.StartTime = DateTime.Now.ToString(); if (projectInfo.Nameproperty == "LuckyCI") { projectInfo.WorkDirectory += "\\Project"; } if (projectInfo.Nameproperty == "fundbook.rn") { projectInfo.WorkDirectory += "\\android"; } if (projectInfo.Nameproperty == "FirstProject") { projectInfo.WorkDirectory += "\\android"; } log = _projectController.Build(projectInfo.BuildCommand, projectInfo.WorkDirectory, out buildResult, out error, out time); projectInfo.Duration = time; projectInfo.EndTime = DateTime.Now.ToString(); projectInfo.Log = (configInfo.StandarOutput == "true") ? ("\n" + log + "\n" + error) : ("\n" + error); projectInfo.Result = buildResult; } } return(projectInfo); }
/// <summary> /// 执行编译项目的操作 /// </summary> /// <param name="projectInfo">当前编译的项目</param> /// <returns></returns> private ProjectInfo BuildProject(ProjectInfo projectInfo) { string buildResult; //存储编译是否成功 string error; //存储编译的日志文件 string log; //存储编译的所有信息 string time; //存储运行的时间 ConfigInfo configInfo = _configController.ConfigQuery("config/preferences", "../../../common/res/CIConfig.xml"); projectInfo.BuildTime = DateTime.Now.ToString(); log = _projectController.Build(projectInfo.BuildCommand, projectInfo.WorkDirectory, out buildResult, out error, out time); projectInfo.Duration = time; //projectInfo.Duration = Regex.Match(log, "(?<=Total time:).*?(?=secs)").Value == "" // ? "" // : (Regex.Match(log, "(?<=Total time:).*?(?=secs)").Value + " secs"); projectInfo.Revision = _latestRevision; projectInfo.Log = (configInfo.StandarOutput == "true") ? ("\n" + log + "\n" + error) : ("\n" + error); projectInfo.Result = buildResult; return(projectInfo); }