Git 从Azure应用程序服务将文件推送到Bitbucket存储库?
我想将文件从Azure应用程序服务上的文件夹推送到Git存储库 我已将本地git repo复制到服务器,并使用LibGit2Sharp提交和推送这些文件:Git 从Azure应用程序服务将文件推送到Bitbucket存储库?,git,azure,bitbucket,libgit2sharp,Git,Azure,Bitbucket,Libgit2sharp,我想将文件从Azure应用程序服务上的文件夹推送到Git存储库 我已将本地git repo复制到服务器,并使用LibGit2Sharp提交和推送这些文件: using (var repo = new Repository(@"D:\home\site\wwwroot\repo")) { // Stage the file Commands.Stage(repo, "*"); // Create the committer's signature and commit
using (var repo = new Repository(@"D:\home\site\wwwroot\repo"))
{
// Stage the file
Commands.Stage(repo, "*");
// Create the committer's signature and commit
Signature author = new Signature("translator", "example.com", DateTime.Now);
Signature committer = author;
// Commit to the repository
Commit commit = repo.Commit($"Files updated {DateTime.Now}", author, committer);
Remote remote = repo.Network.Remotes["origin"];
var options = new PushOptions
{
CredentialsProvider = (_url, _user, _cred) =>
new UsernamePasswordCredentials
{
Username = _settings.UserName,
Password = _settings.Password
}
};
repo.Network.Push(remote, @"+refs/heads/master", options);
}
它可以工作,但似乎需要一段时间,这似乎有点笨重。是否有更有效的方法通过代码实现这一点,或者直接通过Azure(配置或Azure函数)?如果是Azure应用程序,您仍然可以捆绑嵌入式EXE,下面的链接上有一个可移植的Git 你应该把它和你的应用捆绑在一起,并创建一个批处理文件。然后你应该用C代码启动它 附言:学分 另一个谈论类似事情的线索
我认为,你应该使用Azure存储,而不是应用服务的本地磁盘,因为以后当你必须缩小服务时,D:\home\site\wwwroot\repo文件夹中的一些内容可能会丢失,如果你向外扩展,不同的实例在此文件夹中会有不同的内容 如果您检查应用程序服务控制台:
您可以看到git已经预装,因此您不需要任何lib或portable git,您可以使用System.Diagnostics.Process.Start()方法运行git命令。为什么不设置git config并使用cli?@JamesP,似乎可以在Azure应用程序服务中运行exe,你可以在代码@JamesP中嵌入git-portable,你有机会看看这些链接吗?
static void ExecuteCommand(string command)
{
var processInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;
var process = Process.Start(processInfo);
process.OutputDataReceived += (object sender, DataReceivedEventArgs e) =>
Console.WriteLine("output>>" + e.Data);
process.BeginOutputReadLine();
process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) =>
Console.WriteLine("error>>" + e.Data);
process.BeginErrorReadLine();
process.WaitForExit();
Console.WriteLine("ExitCode: {0}", process.ExitCode);
process.Close();
}