Search code examples
tfsbuildazure-devopsazure-pipelinestfsbuild

How to clone code from multiple sources in TFS 2017?


My code is in TFS repository but due to some reason few files are in Sharepoint/MS Teams, how can we clone code from both the sources in the build definition.

Get Sources task is the default which clones the specified TFS repository, is there a way to add or edit this task to clone code from Sharepoint at the same time.


Solution

  • You cannot edit the Get Sources task to clone code from sharepoint.

    However, you can use a powershell task to download the files from the sharepoint.

    For example, add a powershell task in your pipeline to run below inline scripts:

    Using WebClient

    $SharePointFile = "https://the.server/path/to/the/file.txt"
    $Path = "$(Build.SourcesDirectory)\file.txt"
    
    #User Information
    $Username = "userName"
    $Password = "password"
    
    #Download Files
    $client = New-Object System.Net.WebClient
    $client.Credentials = New-Object System.Net.Networkcredential($UserName, $Password)
    $client.DownloadFile($SharePoint, $Path)
    $client.Dispose()
    

    Using Invoke-WebRequest

    $User = "userName"
    $PWord = ConvertTo-SecureString -String "password" -AsPlainText -Force
    $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
    
    $url = 'https://the.server/path/to/the/file.txt'
    $outfile = "$(Build.SourcesDirectory)\file.txt"
    Invoke-WebRequest -Uri $url -OutFile $outfile -Credential $Credential 
    

    Above script will download the file from your sharepoint server to the source code folder $(Build.SourcesDirectory) on the agent machine (ie. c:\agent_work\1\s)

    You can also use SharePoint Pnp PowerShell Framework to download the files in powershell task. See example in this blog.