Jagrati Modi
Jagrati Modi

Reputation: 2088

How to push build artifacts to Git repository using PowerShell script during Azure DevOps build?

I am new to Azure DevOps and learning and want to push a file from builds artifact directory to git repository. I am using this inline PowerShell script to do so:

Write-Host "Hello World"
write-host " Staging directory "$(build.artifactstagingdirectory)
git config --global user.email <useremail>
git config --global user.name <username>
git status
$CurrentPath = Get-Location
write-host "current path" $CurrentPath
$PackagePath =new-item -type directory $(get-date -f MM-dd-yyyy_HH_mm_ss)
$PackageZipPath = "$(build.artifactstagingdirectory)\<artifact to be copied>"
Copy-Item $PackageZipPath -Destination $PackagePath 
git add .
git commit -m "Adding file"
git push origin master
git status
write-host "Package Uploaded to GitHub"

But I am getting this error and not able to push the file in repo:

fatal: could not read Password for 'https://<username>@dev.azure.com': terminal prompts disabled

Am I missing the obvious? How should I use PAT/Password to authenticate?

Upvotes: 0

Views: 3188

Answers (1)

Shayki Abramczyk
Shayki Abramczyk

Reputation: 41545

It's not recommended to store artifacts in Git!

But if you must to do it and you want the push will work, so in the git push line put the username & password:

git push https://username:[email protected]/repo.git master

In the azure-devops.com/repo.git put the repo url (it's replace the origin).

You can also use PAT (instead of username & password) in this way:

git push https://Personal%20Access%20Token:{TokenHere}@azure-devops.com/repo.git master

Upvotes: 1

Related Questions