0

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?

3
  • First I would wonder why you want to commit your build artifact to source control. Then I would suggest you mark the option that scripts are allowed to access the OAuth token. See this answer and this Azure document. Commented Apr 19, 2019 at 13:44
  • 2
    You should not be putting build outputs in source control under any circumstances. Use the Publish Build Artifacts task, or turn the artifact into a package (i.e. a NuGet package) and push it to an artifacts feed. Commented Apr 19, 2019 at 13:46
  • I think this walkthrough is what you want to do so that you don't end up putting passwords or PATs in your pipeline. Again, if you have a use case where putting build artifacts in source control provides value, you have a broken process and need to rethink why you need this. Commented Apr 19, 2019 at 13:55

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.