获取分支名称到代码中

Ana*_*and 4 c# git visual-studio

我有一个关于将分支名称作为字符串传递给我的代码的问题。

所以我们使用的是 git 存储库,分支号也指构建所在的暂存环境。意思是,如果我的分支是 001,我的 url 是 001.test.myapplication.com。

我正在编写在分支的登台环境中执行的自动化测试。我的问题是,是否可以将分支编号传递给我的代码,以便我可以将其作为我要测试的 URL 的一部分?

我正在使用 Visual Studio 2017、selenium 和 specflow。

Ana*_*and 12

I actually found a great solution which perfectly works. Sharing so in the future, others can use it too if they need to.

        ProcessStartInfo startInfo = new ProcessStartInfo("git.exe");

        startInfo.UseShellExecute = false;
        startInfo.WorkingDirectory = "dir Here";
        startInfo.RedirectStandardInput = true;
        startInfo.RedirectStandardOutput = true;
        startInfo.Arguments = "rev-parse --abbrev-ref HEAD";

        Process process = new Process();
        process.StartInfo = startInfo;
        process.Start();

        string branchname = process.StandardOutput.ReadLine();
Run Code Online (Sandbox Code Playgroud)

  • 这对我来说非常有效。我建议将流程工作包装在 using 语句中。 (2认同)