在脚本的同目录下需要创建一个名为“add-list.txt”的文件,用于存放需要创建的projects,运行时要输入projects需要加入的指定组的ID,也可以都扔到一个组中,建完projects后直接transfer到相关组。
#/usr/bin/Python27
# coding=utf-8
import gitlab
gl = gitlab.Gitlab('http://10.50.30.33/', private_token='fffghjjjkkllljwj')
gid = int(raw_input('GroupID: ')) #project需要放置的Group的ID
group = gl.groups.get(gid)
print group.name
pid = []
path = 'add-list.txt'
with open(path,'r') as f:
for line in f.readlines():
serv = line.strip()
project = gl.projects.create({'name': serv, 'namespace_id': gid,'path':serv})
branch = project.branches.create({'branch': 'develop','ref': 'master'}) #创建分支1:develop,可以自己修改
branch = project.branches.create({'branch': 'qa_release','ref': 'develop'}) #创建分支2:qa_release,可以自己修改调整
branches = project.branches.list()
print project.name,project.id,branches
pid.append(project.id)
for num in pid:
i = int(num)
project = gl.projects.get(i)
project.default_branch = 'develop' #设置默认分支为develop,可自行修改
project.save()
print project.name,project.http_url_to_repo,project.default_branch
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。