Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To create a file in Azure Pipeline and save it in SharePoint using the command line, follow these steps:

  1. First, ensure that you have the necessary permissions and access to the SharePoint site where you want to save the file.

  2. In your Azure Pipeline, add a Command Line task.

  3. In the Command Line task, use the echo command to create the content of the file. For example, to create a new file named example.txt with the content Hello World!, you can use the following command:

echo "Hello World!" > example.txt
  1. Next, use the SharePoint REST API to upload the file to the SharePoint site. You can use the curl command to make a POST request to the SharePoint site. The command should look like the following:
curl --ntlm -u username:password -T example.txt "https://yourdomain.sharepoint.com/sites/yoursite/_api/web/GetFolderByServerRelativeUrl('/Shared%20Documents/')/Files/add(url='example.txt',overwrite=true)"

Replace username and password with your SharePoint credentials. Replace yourdomain.sharepoint.com with the URL of your SharePoint site, and yoursite with the name of the SharePoint site. In the example above, the file is saved in the Shared Documents folder. You can change the folder by modifying the GetFolderByServerRelativeUrl parameter.

  1. Save and run your pipeline. The new file should now be uploaded to your SharePoint site.