I currently have a shell script that I want to use as part of a Jenkins/Docker job that clones all of the repos from my organization that are tagged with a specific language.
curl -s -H "Authorization: token "$token"" https://github.[company].com/api/v3/orgs/$org/repos\?page\=$i\&per_page\=100 |
jq '.[] | select(.language != null) | select(.language | contains("'$lang'")).ssh_url' | xargs -n 1 git clone
For most instances it works but I realized that I need to have SSH configured in the Docker container for it to work properly. Rather than dealing with trying to get that set up, I found I can still clone using HTTPS with a user:token combo.
git clone https://user:token@github.[company].com/organization/repo.git
My issue is that I am getting a list of all of the target repos and cloning them, so I need to pass the user:token somehow for each one. I know I can get the clone_url instead of the ssh_url but I do not know how to insert the credentials. I have looked around a lot but have not found anything that is helping me with this issue. Does anyone know if and how I can format the script so it passes the credentials in the URL?
Thanks
I suppose I was looking at the wrong part of the script for the formatting. I ended up using sed on the curl/jq output to format the url before using xargs to git clone.
sed 's,https://,https://user:token@,g'