Reputation: 853
I'm trying to upload a file to my gitlab repository using this way:
x = project.upload("Jenkinsfile", filepath="./Jenkinsfile")
however it not work for me, so
x1 = project.upload("Jenkinsfile", filepath="/media/conde/Trabajo/Trabajo/DevOps/BOMH/bomh/Jenkinsfile")
, not work, let's go to trying the documentation example because it not need a filesystem path, so it have at least to create a new file empty:
x2 = project.upload("filename.txt", filedata="data")
But never a file is uploaded. The output of each comand is:
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'}
What is wrong, the documentation, the API? I can create the repository, the branchs and create some files, but not upload a file from my computer.
Upvotes: 1
Views: 2023
Reputation: 853
The truth that described in the documentation can be a bit ambiguous, the question is that the function project.upload not upload a file to the remote repository in Gitlab, just upload a file to the project, if you want to directly upload any initial file (like me that I'm automatically creating a initial gitlab repository with some files for a project using python-gitlab) a good solution is transfer the content from your local file to the new file that you are creating. In my case I did this:
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': '[email protected]',
'author_name': user_nick,
#'encoding': 'utf-8',
'commit_message': 'Create template.json'})
Upvotes: 5