Score:2

How to authenticate and push to GitHub from a CI Script

fr flag

I keep my development on a personal GitLab server. In my CI/CD script, I want to push the repository to a public GitHub repo when a new tag is created.

The CI/CD runs in an ephemeral Docker container, so there are no credentials stored. I can however add secrets in GitLab, but I don't know what git command I would use to log in to GitHub pragmatically.

I have tried git push https://usesrname:[email protected]/myrepo but that gives me an Authentication failed error.

Any ideas?

Score:4
us flag

You should create a new personal access token for your CI pipeline. Just go to https://github.com/settings/tokens to create it. You need to give the repo scope to the new token.

Then you can use https://<username>:<token>@github.com/myrepo to push.

Note: That token is dangerous, it allows full control to your repos just like your password.

fr flag
Thank you. I am going to add the username and password to GitLab secrets, so it won't be shown, even in the CI logs.
mx flag
@vaizki seems like this has been deprecated `Support for password authentication was removed on August 13, 2021`
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.