/// <summary> /// Get the Clone CMD /// </summary> /// <returns>Clone CMD</returns> private string cloneCmd() { Config.PrebuildConfig cfg = Config.getDataForBuild(buildInfo); String sCmd = ""; // Change to drive sCmd = sProjectDir.Substring(0, 1) + ":"; // Change to directory sCmd += " && cd " + System.IO.Directory.GetParent(sProjectDir.TrimEnd('\\')).FullName; if (cfg.NewRepoInit == "") { // Git Clone sCmd += " && git clone " + buildInfo.repo_url + " " + Path.GetFileName(sProjectDir.TrimEnd('\\')); // Change to directory sCmd += " && cd " + sProjectDir; // Git Checkout sCmd += " && git checkout " + buildInfo.sha; } else { sCmd += " && " + cfg.NewRepoInit; } return(sCmd); }
/// <summary> /// Get the Fetch CMD /// </summary> /// <returns>Fetch CMD</returns> private string fetchCmd() { String sCmd = ""; // Change to drive sCmd = sProjectDir.Substring(0, 1) + ":"; // Change to directory sCmd += " && cd " + sProjectDir; Config.PrebuildConfig cfg = Config.getDataForBuild(buildInfo); if (cfg.ExistingRepoInit == "") { // Git Reset sCmd += " && git reset --hard"; // Git Clean sCmd += " && git clean -f"; // Git fetch sCmd += " && git fetch"; // Git Checkout sCmd += " && git checkout " + buildInfo.sha; } else { sCmd += " && " + cfg.ExistingRepoInit; } return(sCmd); }
/// <summary> /// Initialize project dir and checkout repo /// </summary> private void initProjectDir() { string sProjectsDir = System.IO.Directory.GetParent(sProjectDir).FullName; // Check if projects directory exists if (!Directory.Exists(sProjectsDir)) { // Create projects directory Directory.CreateDirectory(sProjectsDir); } // Check if already a git repo if (Directory.Exists(sProjectDir + @".git") && buildInfo.allow_git_fetch) { //string status = String.Format("Git repo exists ({0}) and fetch command is allowed (allow_git_fetch={1})", sProjectDir + @".git", Convert.ToString(buildInfo.allow_git_fetch)); //commands.AddLast("echo \"" + status + "\""); // Already a git repo, pull changes commands.AddLast(fetchCmd()); } else { // No git repo, checkout if (Directory.Exists(sProjectDir)) { DeleteDirectory(sProjectDir); } commands.AddLast(cloneCmd()); } Config.PrebuildConfig cfg = Config.getDataForBuild(buildInfo); if (cfg.PostPrepare != "") { commands.AddLast(cfg.PostPrepare); } }
/// <summary> /// Constructor /// </summary> /// <param name="buildInfo">Build Info</param> public Build(BuildInfo buildInfo) { this.buildInfo = buildInfo; Config.PrebuildConfig cfg = Config.getDataForBuild(buildInfo); if (cfg.ProjectDir != "") { if (Path.IsPathRooted(cfg.ProjectDir)) { sProjectDir = cfg.ProjectDir; } else { sProjectDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\" + cfg.ProjectDir; } } sProjectDir = sProjectDir.EndsWith(@"\") ? sProjectDir : sProjectDir + @"\"; commands = new LinkedList <string>(); outputList = new ConcurrentQueue <string>(); completed = false; commands.AddFirst("echo \"Project directory is set to: " + cfg.ProjectDir + "\""); }