I am attempting to use GitAliases to commit some changes to my Git repo from a cake script on Jenkins. I have been able to overcome the lack of descriptive information and examples for the methods and arguments in the documentation (https://cakebuild.net/api/Cake.Git/GitAliases/) for GitAdd(), GitCommit(), and GitTag(), all of which are working successfully now, but I am not able to get GitPush() nor GitPushRef() to work no matter what I try.
#addin "nuget:https://www.nuget.org/api/v2?package=Cake.Git";
using System;
using System.IO;
var gitUserName = Argument("gitUserName","userName");
var gitUserPassword = Argument("gitUserPassword","");
var gitEmail = Argument("gitEmail","[email protected]");
var gitBranchName = Argument("gitBranchName","feature/test-git");
Task("Git:CommitAndPush")
.Does(() =>
{
var rootPath = "./..";
Information($"Commit and Push {rootPath}");
Information("Staging all updated files in /available, /extracted, and /src directories...");
var toAdd = new FilePath[]
{
new FilePath(Path.Combine(rootPath, "available")),
new FilePath(Path.Combine(rootPath, "extracted"))
};
GitAdd(rootPath, toAdd);
Information("Committing files...");
var commit = GitCommit(rootPath, gitUserName, gitEmail, "Commit message");
Information($"Pushing changes for commit {commit}...");
// TODO: Cannot get any of these to work!
//GitPush(rootPath);
//GitPush(rootPath, gitUserName, gitUserPassword);
//GitPush(rootPath, gitUserName, gitUserPassword, gitBranchName);
//var gitTag = "myTag";
//GitTag(rootPath, gitTag);
//GitPushRef(rootPath, "origin", gitTag);
//GitPushRef(rootPath, gitUserName, gitUserPassword, "origin", gitTag);
Information("Git process complete!");
});
I have tried every overload of GitPush() and GitPushRef() including creating a tag and pushing the tag using GitPushRef() but no luck. I can see the commit is successful locally, and the tag gets created, but the Push always fails. The most common error I am getting is:
"Error: One or more errors occurred. unsupported URL protocol"
The Git user account uses SSH.
Cake Git uses libgit2sharp for git operations, which doesn't support SSH.
There's an open issue for it on libgit2sharp GitHub repo https://github.com/libgit2/libgit2sharp/issues/1422