0

I want to push my code using jenkins pipeline, so is there any way to use git push with HTTPS from jenkins?

Can we use GitHub personal token for git push?

1 Answer 1

2

There are many different ways to achieve this goal. I use sh steps to run git commands.

After staging and committing the changes locally, the push command will look like

def repoUrlWithAuth = "https://<username>:<token>@github.com/<username>/<repo>.git"
def sourceBranch = "<branch-to-push-to>"

git push --repo=${repoUrlWithAuth} --set-upstream ${repoUrlWithAuth} ${sourceBranch}

If the initial cloning is done using https://<username>:<token>@github.com/<username>/<repo>.git, then the credentials will remain on the git config and you don't need to include --repo=${repoUrlWithAuth}.

If the initial cloning has the correct local-remote branch mapping, then you don't need to include --set-upstream ${repoUrlWithAuth} ${sourceBranch}

There is another answer here that might be of help to figure this out.

Sign up to request clarification or add additional context in comments.

1 Comment

In my case, I used github app credentials to checkout, in the pipeline, I wanted to push at some point. I had to wrap with credentials and then git remote remove origin followed by git remote add origin ${repUrlWithAuth} and then I could run git push origin branch.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.