首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Cake Build (C# Make)推送提交到Azure Repo

使用Cake Build (C# Make)推送提交到Azure Repo
EN

Stack Overflow用户
提问于 2021-05-24 20:00:01
回答 1查看 71关注 0票数 0

我正在尝试用蛋糕来推动一个项目中的变化。这是我的代码

代码语言:javascript
复制
[TaskName("GitPush")]
public sealed class GitPushTask : FrostingTask<BuildContext>
{
    public override void Run(BuildContext context)
    {
        context.GitAddAll(context.WorkDirectoryPath);
        context.GitCommit(context.WorkDirectoryPath, "user surname", "usersurname@hellow.com", "Testing Commit");
        context.GitPush(context.WorkDirectoryPath, context.GitUsername, context.GitPassword);
    }
}

GitAddAll和GitCommit工作得很好,但在GitPush中我得到了这个错误:

代码语言:javascript
复制
An error occurred when executing task 'GitPush'.
Error: LibGit2Sharp.LibGit2SharpException: No error message has been provided by the native library
   at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
   at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result)
   at LibGit2Sharp.Core.Proxy.git_remote_push(RemoteHandle remote, IEnumerable`1 refSpecs, GitPushOptions opts)
   at LibGit2Sharp.Network.Push(Remote remote, IEnumerable`1 pushRefSpecs, PushOptions pushOptions)
   at LibGit2Sharp.Network.Push(Remote remote, String pushRefSpec, PushOptions pushOptions)
   at LibGit2Sharp.Network.Push(IEnumerable`1 branches, PushOptions pushOptions)
   at Cake.Git.GitAliases.<>c__DisplayClass32_0.<GitPush>b__0(Repository repository)
   at Cake.Git.Extensions.RepositoryExtensions.UseRepository(ICakeContext context, DirectoryPath repositoryPath, Action`1 repositoryAction)
   at Cake.Git.GitAliases.GitPush(ICakeContext context, DirectoryPath repositoryDirectoryPath, String username, String password)
   at GitPushTask.Run(BuildContext context) in C:\Users\jmedingr\Desktop\MonEES.CICD.Cake\cake\Program.cs:line 128
   at Cake.Frosting.FrostingTask`1.Cake.Frosting.IFrostingTask.RunAsync(ICakeContext context)
   at Cake.Core.CakeTask.Execute(ICakeContext context)
   at Cake.Core.DefaultExecutionStrategy.ExecuteAsync(CakeTask task, ICakeContext context)
   at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report)
   at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report)
   at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report)
   at Cake.Core.CakeEngine.RunTask(ICakeContext context, IExecutionStrategy strategy, CakeTask task, String target, Stopwatch stopWatch, CakeReport report)
   at Cake.Core.CakeEngine.RunTargetAsync(ICakeContext context, IExecutionStrategy strategy, ExecutionSettings settings)
   at Cake.Cli.BuildScriptHost`1.RunTargetAsync(String target)
   at Cake.Core.Scripting.ScriptHost.RunTarget(String target)
   at Cake.Frosting.Internal.FrostingEngine`1.Run(String target)
   at Cake.Frosting.Internal.DefaultCommand.Execute(CommandContext context, DefaultCommandSettings settings)

我猜这个错误是因为我在Azure Repo上认证的方式有问题,但我找不到方法或添加到使用azureRepo的工作查找……

EN

回答 1

Stack Overflow用户

发布于 2021-05-25 04:22:14

你有没有尝试过手动提交和推送?我在执行你给出的例子时没有任何问题。

我创建了一个这样的PAT:

注意:设置了Code: Read&Write

然后,我使用了上面指定的代码,只做了明显的修改:(当密码设置为PAT时,不使用用户名)

代码语言:javascript
复制
public override void Run(BuildContext context)
{
    var pat = context.EnvironmentVariable("MYPAT");
    if (string.IsNullOrEmpty(pat))
    {
        throw new Exception("MYPAT must be set!");
    }
    
    context.GitAddAll(context.WorkDirectoryPath);
    context.GitCommit(context.WorkDirectoryPath, "Nils", "nils@hellow.com", "Testing Commit");
    context.GitPush(context.WorkDirectoryPath, "unused when password is a PAT", pat);
}

然后,结果如下所示:

代码语言:javascript
复制
❯ git log
commit 5979345845c7d3d7c6387ea7aff74a1de3ae366c (HEAD -> main, origin/main, origin/HEAD)
Author: Nils <nils@hellow.com>
Date:   Mon May 24 22:03:12 2021 +0200

    Testing Commit
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67671723

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档