I’m working on a CI/CD pipeline using Jenkins, where part of the process involves uploading build artifacts to an intranet SharePoint. Currently, I have two possible approaches in mind:
Using the SharePoint REST API: modify the Jenkinsfile to include a step that
uses curl
(or a similar tool) to send files to SharePoint, treating
it like a REST API. I prefer this approach as it keeps the pipeline
configuration entirely as code.
Using OneDrive sync: install OneDrive on the server hosting Jenkins, configure a local folder to sync with a SharePoint folder, and have the pipeline drop artifacts into this local folder.
My concerns are:
Are there better alternatives for integrating Jenkins with SharePoint for artifact upload? If not, which of these approaches is more reliable and maintainable in the long term?
SharePoint does provide a Rest API to upload files.
Example REST API Request:
POST /sites/your-site/_api/web/GetFolderByServerRelativeUrl('/sites/your-site/your-library')/Files/Add(url='your-file-name.zip', overwrite=true)
Host: your-sharepoint-site.sharepoint.com
Authorization: Bearer your-access-token
Content-Type: application/octet-stream
Content-Length: your-file-size
(binary content of your-file-name.zip)
Reference: