gitlab-ci过程中使用过的gitlabAPI 记录

2018-12-19  文晶 

1、官方及参考文档

https://docs.gitlab.com/ce/ci/triggers/README.html#pass-job-variables-to-a-trigger

https://walterinsh.github.io/2016/04/18/using-gitlab-ci.html

http://blog.csdn.net/wmq880204/article/details/52474275#t7

https://docs.gitlab.com.cn/ce/ci/quick_start/README.html  中文文档

https://docs.gitlab.com/ee/api/README.html API入口


2、gitlab-ci过程中使用到api 记录

gitlab token

personal-token:PN-token    wenjing


curl https://gitlab.xx.com/api/v4/projects?private_token=PN-token



取得所有项目


 curl --header "Private-Token: PN-token" http://gitlab.xx.com/api/v4/projects


curl --header "Private-Token: PN-token" http://gitlab.xx.com/api/v4/projects/559


按名称查项目id

curl http://gitlab.xx.com/api/v4/projects?private_token=PN-token&search=virtual_project

curl --header "Private-Token: PN-token" http://gitlab.xx.com/api/v4/projects?search=test



按项目ID查询trriger-token

curl --header "PRIVATE-TOKEN: PN-token" "http://gitlab.xx.com/api/v4/projects/559/triggers"


为没有trigger-token 项目创建token

curl --request POST --header "PRIVATE-TOKEN: PN-token" --form description="通过api增加trrigertoken" "http://gitlab.xx.com/api/v4/projects/600/triggers"


创建项目

curl --request POST --header "PRIVATE-TOKEN: PN-token" --form name="create_project_byapi" "http://gitlab.xx.com/api/v4/projects"

删除项目

curl --request DELETE --header "PRIVATE-TOKEN: PN-token"  "http://gitlab.xx.com/api/v4/projects/657"

查看pipline

curl --header "PRIVATE-TOKEN: PN-token" "http://gitlab.xx.com/api/v4/projects/603/pipelines"


创建pipline

curl --request POST --header "PRIVATE-TOKEN: PN-token" "http://gitlab.xx.com/api/v4/projects/603/pipeline?ref=master"


先有.gitlab-ci.yaml 文件才能创建pipline

添加gitlab-ci.yml文件

curl --request POST --header 'PRIVATE-TOKEN: PN-token' 'http://gitlab.xx.com/api/v4/projects/603/repository/files/.gitlab-ci.yml?branch=master&author_email=author%40example.com&author_name=wenjing.li&content=ymalbyapi&commit_message=addymalfile'


git clone git@gitlab.xx.com:wenjing/testcreatetriggertoken.git

cd testcreatetriggertoken

touch README.md

git add README.md

git commit -m "add README"

git push -u origin master


追加文件内容 推送到

文件内容根据依赖关系生成触发执行脚本


.gitlab-ci.yml逻辑

1、获取当前版本号

查看runner

curl --header "PRIVATE-TOKEN: PN-token "http://gitlab.xx.com/api/v4/runners"

id=19


给项目执行runner

curl --request POST --header "PRIVATE-TOKEN: PN-token" "http://gitlab.xx.com/api/v4/projects/603/runners" --form "runner_id=19"


创建pipline—及执行

curl --request POST --header "PRIVATE-TOKEN: PN-token" "http://gitlab.xx.com/api/v4/projects/603/pipeline?ref=master"


获取指定pipline信息

curl --header "PRIVATE-TOKEN: PN-token" "http://gitlab.xx.com/api/v4/projects/603/pipelines/1178"



获取项目pipelines

curl --header "PRIVATE-TOKEN: PN-token" "http://gitlab.xx.com/api/v4/projects/603/pipelines"


触发pipline执行retry

curl --header "PRIVATE-TOKEN: PN-token" "http://gitlab.xx.com/api/v4/projects/603/pipelines/1178/retry"


获得triiger_token

curl --header "Private-Token: PN-token" http://gitlab.xx.com/api/v4/projects/559/triggers


创建trigger_token

curl --request POST --header "PRIVATE-TOKEN: PN-token" --form description="my description" "http://gitlab.xx.com/api/v4/projects/1/triggers"



得到项目部署信息

curl --header "PRIVATE-TOKEN: PN-token" "http://gitlab.xx.com/api/v4/projects/559/deployments"


创建hookup

POST /projects/:id/hooks



676°/6758 人阅读/1 条评论 发表评论

熊志男  2018-12-27

不错,收藏


登录 后发表评论