Forum Discussion

amitaiemd's avatar
amitaiemd
Copper Contributor
Jul 13, 2023

How to upload a file to a folder present in TFVC repo from an Azure pipelines.yml file

Hi Team,

Can you please help me with powershell rest API, to upload a file to a folder in TFVC(TFS) repo from an Azure pipelines.yml file .

Thanks

1 Reply

  • Below the step by step:

     

    1. Prepare Your YAML Pipeline

     

    trigger:
    - main
    
    pool:
      vmImage: 'windows-latest'
    
    steps:
    - task: PowerShell@2
      inputs:
        targetType: 'inline'
        script: |
          # Set working directory
          cd "$(Build.SourcesDirectory)"
    
          # Create a sample file
          echo "Hello from pipeline" > newfile.txt
    
          # Add the file to TFVC
          tf add newfile.txt
    
          # Check in the file
          tf checkin newfile.txt /comment:"Added via pipeline" /recursive /force /loginType:OAuth /login:.,$env:SYSTEM_ACCESSTOKEN
      env:
        SYSTEM_ACCESSTOKEN: $(System.AccessToken)

     

    1. Important Configuration Notes
    • Make sure “Allow scripts to access OAuth token” is enabled in your pipeline settings.
    • The agent must have Visual Studio or the TFVC command-line tools installed (tf.exe).
    • You must have proper workspace mappings set up for TFVC to know where to check in the file.

Resources