Jenkins Job to create Merge Request


Our team is developing a Jenkins job using which we can create Merge/Pull request when we are merge dev branch to release branch in our repo. This job will do this task for 32 repos at once as all repos have same branch names.

Now, I am using following command in Jenkins Build Step > Execute Shell to create merge request.

git push -v --push-option=‘merge_request.create’ origin ${SourceBranch}:${TargetBranch}

Now Instead of creating Merge request, it is directly merging the two branches.

Please help me to solve this problem.

Thanks in advance.

Hi @aman0035

git push origin ${SourceBranch}:${TargetBranch} pushes changes on local branch ${SourceBranch} directly to the origin/${targetBranch}, there is no Merge request involved at all.

The command should look like this if the branch already exists on the remote git push -o merge_request.create -o${TargetBranch} origin assuming you are on the ${SourceBranch}

Thank you for your response. I am getting following error.

  • git checkout origin/dev1
    HEAD is now at 980faad test2

  • git push -o merge_request.create -o origin
    fatal: You are not currently on a branch.
    To push the history leading to the current (detached HEAD)
    state now, use

    git push origin HEAD:

However, following is my code in Jenkins.
echo “starting Push”
git checkout ${SourceBranch}
git push -o merge_request.create -o${TargetBranch} origin

Did this for testing, but it did not create any merge request.

Started by user Ammy Running as SYSTEM Building in workspace /var/jenkins_home/workspace/test1-8April22 > git --version # timeout=10 > git --version # ‘git version 2.30.2’ [test1-8April22] $ /bin/sh -xe /tmp/ + git clone -b dev1 --depth=5 Cloning into ‘repo’… + cd repo + git status On branch dev1 Your branch is up to date with ‘origin/dev1’. nothing to commit, working tree clean + git push -o merge_request.create -o****/sample-repo.git?ref=main origin

Everything up-to-date Finished: SUCCESS

I was able to fix it other way around.
I simply created new branch pushed it.

git pust source-branch:new-dynamic-branch

and this created a new branch and also created a merge request