How can I git clone from powershell without entering credentials?
What I am trying to do is create one of the steps in the CI pipeline that is responsible for git operations. Suppose an external user provides a git url, username and password. I would like to have something like this:
function Get-GitClone{
param([string]$URL,
[string]$username,
[string]$password
)
# Create temp folder
cd C:\Temp
mkdir GitTemp
# Clone TFD Git repository
git clone $URL
}
What I am getting is an error when running this script, simply because you run this from powershell it will ask for credentials. I've tried git -credential-winstore.exe but it still needs google user interaction doesn't help either, or I just can't find anything useful.
Thank you in advance
source to share
Are you using ssh or https?
If you are using ssh you can run the key agent (for example pageant + make git use plink), you need to tell git to use plink for ssh. below is a snippet of a powershell script file that I am using to set up my environment
#first add putty to PATH environment variable:
[System.Environment]::SetEnvironmentVariable("PATH",($env:Path + ";C:\Program Files (x86)\PuTTY\ "))
#now where.exe shld find plink too!
[System.Environment]::SetEnvironmentVariable("GIT_SSH",(where.exe plink),"Machine")
You will need to run pageant to load the private key, and for that reason, you cannot password protect the script - you can use deploy-key
(without write access to the repo)
if you are not using ssh due to firewall issues - you may need something else
source to share