Gitlab-ci.yml to create merge reqeust

对着背影说爱祢 提交于 2019-12-08 06:58:30

问题


I have the following gitlab-ci.yml file running in DEV branch, with target as DEV as well. Since i couldnt point the TARGET as MASTER, there is no automatic MR getting created. I would like to know if its possible to create a merge request in the gitlab-ci script itself.

dev:
  stage: deploy
  script:
    - url_host=`git remote get-url origin | sed -e "s/https:\/\/gitlab-ci-token:.*@//g"`
    - git remote set-url origin "https://gitlab-ci-token:${CI_TAG_UPLOAD_TOKEN}@${url_host}"
    - databricks workspace export_dir -o /mynotebooks.
    - git add .
    - git commit -m 'Add notebooks to Repo' -a || true
    - git push origin HEAD:dev
  tags:
    - test

I have searched and referred my websites, but couldnt see any notes about programmatically creating Merge Requests.

The idea is various developers are working on a databrick cluster, and gitlab is scheduled to run at regular intervals. The changes would be pushed to DEV branch and will be pushed to MASTER branch using the Merge requests.

I would like to know if this MR creation can be automated. NEW TO GITLAB please.

Thanks.


回答1:


You can create a MR in Gitlab using git push options.

To create a MR to merge dev into master using git, run the following command

git push origin HEAD:dev -o merge_request.create -o merge_request.target=master 

Read more about this feature here.




回答2:


There is actually a better programable way to create MR.

Gitlab has its official Gitlab API you can access to create/update/delete almost anything. Of course doing those HTTP requests by yourself will be tedious. Try use the python library for gitlab to do what you want. You can literally make anything programmable!

Specifically to deal with MR, you can look at this chapter.



来源:https://stackoverflow.com/questions/58322235/gitlab-ci-yml-to-create-merge-reqeust

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!