简体   繁体   中英

Git push from jenkins pipeline

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM