9

I am trying to set up my pipeline to only checkout specific folders related to a project so that I can reduce the checkout time.

I am using the following code found on many other questions but I cannot seem to get it to work.

- script: |
    cd $(Build.SourcesDirectory)

    git init
    git remote set-url origin $(Build.Repository.Uri)
    git config core.sparsecheckout true

    echo STARS/Source/ >> .git/info/sparse-checkout

    git pull origin $(Build.SourceBranch)
  displayName: 'Project Specific Checkout'
  env:
    SYSTEM_ACCESSTOKEN: $(System.AccessToken)

I keep getting the following error in the logs:

Reinitialized existing Git repository in C:/Agent001/_work/20/s/.git/
fatal: Cannot prompt because terminal prompts have been disabled.
fatal: could not read Password for 'https://organization@dev.azure.com/...': terminal prompts disabled

I cannot seem to work out how to enable terminal prompts.

Update:

Based on @Repcak comment I updated my code but still receiving the terminal prompts have been disabled error.

Ross
  • 2,463
  • 5
  • 35
  • 91
  • Its not about enabling terminal prompts because you cannot input something prompted in the AzurePipeline. Some command needs more parameters that you did not provide. Looks like 'git remote add -f origin $(Build.Repository.Uri)' is the issue. Maybe this will help? https://stackoverflow.com/questions/10904339/github-fatal-remote-origin-already-exists – Repcak Nov 12 '20 at 12:39
  • @Repcak I updated my code but still getting the error regarding terminal prompts. – Ross Nov 12 '20 at 13:05
  • what is `SYSTEM_ACCESSTOKEN` ? a token to be added in http headers ? the password for user `organization` ? ... – LeGEC Nov 12 '20 at 13:23
  • This answer might help, https://stackoverflow.com/questions/66470759/set-git-credentials-inside-a-azure-yaml-pipeline – big pop Aug 25 '22 at 07:35
  • I think this might helpful. https://stackoverflow.com/questions/66470759/set-git-credentials-inside-a-azure-yaml-pipeline – big pop Aug 25 '22 at 07:36

3 Answers3

6

The actual issue is not about having an interactive terminal, it is about providing credentials to access the target repository.

The setup to follow depends on how you access the repo (you seem to use https, is ssh an option ?) and to some extent the testing platform, if you intend to use a credential manager on the client side.

  • through https : if SYSTEM_ACCESSTOKEN is a PAT generated for your test environment, you have to somehow use it in your script, as you would with a password.

You can pass the username:password by specifying it in the target url (the url you posted in the error message only has the username part), or set up the credential manager so that it contains the password for said login, or find a way to issue an auth token in some way, or ...

  • if you can switch to ssh access : set up an ssh key for your pipeline, and choose a way to deploy said ssh key on the testing platform.
LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • Can you provide an example command using `username:password` in it? I have access to the repo, just not sure why our old authentication methods suddenly stopped working today. – kayleeFrye_onDeck Jul 07 '21 at 22:15
  • 1
    use it in your http/https url : `https://username:password@example.com/...` – LeGEC Jul 08 '21 at 07:02
4

Not sure if this will solve your problem but I had the same error message in my pipeline which needed to push code into the repo and it was just the steps in my pipeline not being able to access the token for the build.

Did you check the "Allow scripts to access OAuth token" checkbox?

enter image description here

Diskdrive
  • 18,107
  • 27
  • 101
  • 167
4
steps:
- checkout: self
  persistCredentials: true

You can try this.

big pop
  • 51
  • 1