3

What I am trying to do is to create one of the steps in CI pipeline that is responsible for git operations. Let say external user provides git URL, username and password. I'd like to have something like that:

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'm getting is error running this script, simply because is you run this from powershell it will ask for credentials. I have tried git-credential-winstore.exe, but it still needs user interaction Google doesn't help either or I just can't find anything useful.

Thanks in advance

monkzen
  • 227
  • 2
  • 3
  • 5

2 Answers2

2

Have you tried $username:$password@$URL?

0

Are you using ssh or https?

If you use ssh you could launch a key agent (for example pageant + make git use plink) you'd need to instruct git to use plink for ssh. below is a snippet of a powershell script I use to setup 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'd need to launch pageant to load the private key, and you would not be able to password protect for the script, for this reason - you could use a deploy-key (with no write access to the repo)

if you're not using ssh, due to firewall issues - you may need to come up with something else

Vincent De Smet
  • 4,859
  • 2
  • 34
  • 41