Yuva
Yuva

Reputation: 3153

Gitlab-ci.yml to create merge request

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.

Upvotes: 5

Views: 4851

Answers (2)

Brad Pitt
Brad Pitt

Reputation: 416

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.

Upvotes: -1

Murli Prajapati
Murli Prajapati

Reputation: 9713

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 Gitlab's push options for merge requests.

Upvotes: 16

Related Questions