[英]Problem to upload a file to Gitlab using python-gitlab
我正在嘗試使用這種方式將文件上傳到我的 gitlab 存儲庫:
x = project.upload("Jenkinsfile", filepath="./Jenkinsfile")
但是它對我不起作用,所以
x1 = project.upload("Jenkinsfile", filepath="/media/conde/Trabajo/Trabajo/DevOps/BOMH/bomh/Jenkinsfile")
,不起作用,讓我們去嘗試文檔示例,因為它不需要文件系統路徑,所以它至少要創建一個空的新文件:
x2 = project.upload("filename.txt", filedata="data")
但從不上傳文件。 每個命令的輸出是: x={'url': '/uploads/c52cf003900c7afe6843909317049cc3/Jenkinsfile', 'markdown': 'Jenkinsfile', 'alt': 'Jenkinsfile'}
x1 = {'url': '/uploads/c52cf003900c7afe6843909317049cc3/Jenkinsfile', 'markdown': 'Jenkinsfile', 'alt': 'Jenkinsfile'}
x2 = {'url': '/uploads/3c2a389555609ba08c3bd54bee0e7339/filename.txt', 'markdown': 'filename.txt', 'alt': 'filename.txt'}
有什么問題,文檔,API? 我可以創建存儲庫、分支並創建一些文件,但不能從我的計算機上傳文件。
文檔中描述的事實可能有點模棱兩可,問題是函數project.upload在Gitlab中沒有上傳文件到遠程存儲庫,只是上傳文件到項目,如果你想直接上傳任何初始文件(就像我一樣,我正在使用 python-gitlab 為項目自動創建一個包含一些文件的初始 gitlab 存儲庫)一個好的解決方案是將內容從本地文件傳輸到您正在創建的新文件。 就我而言,我這樣做了:
with open('./file_to_upload', 'r') as my_file:
file_content = my_file.read()
f = project.files.create({'file_path': 'template.json',
'branch': 'master',
'content': file_content,
'author_email': 'test@example.com',
'author_name': user_nick,
#'encoding': 'utf-8',
'commit_message': 'Create template.json'})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.