Ask Your Question
3

How can I use the command line to create a file in Azure pipeline and save it in SharePoint?

asked 2023-07-12 15:05:22 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-07-12 15:32:01 +0000

qstack gravatar image

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.
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-12 15:05:22 +0000

Seen: 10 times

Last updated: Jul 12 '23