Jenkins pipeline with GitLab

I want to merge a branch with the controller (m a s t e r) branch. How do I build a pipeline to perform this operation automatically? I want to manually run this job whenever needed. I don’t need any webhook trigger.

I connect Jenkins using a SSH key. I created a pipeline.
Checkout the branch ‘my-branch’
git checkout controller
git merge my-branch
git push origin controller

It throws “not something we can merge”. What is the issue here?

This could be because the branch does not exist, or because it is not fetched in your local repository. Here is an untested example with the steps to create a Jenkins pipeline to merge a branch with the controller branch:

  1. First, ensure that the branch my-branch exists and is available in your local repository. You can fetch the branch using the command git fetch origin my-branch.
  2. Create a new Jenkins Pipeline job.
  3. In the Pipeline section of the job configuration, choose “Pipeline script” and enter the following script:
pipeline {
    agent any

    stages {
        stage('Merge branch') {
            steps {
                script {
                    // Checkout the controller branch
                    git branch: 'controller', credentialsId: 'your-credentials-id', url: 'your-repo-url'

                    // Merge the 'my-branch' into the 'controller' branch
                    sh 'git merge origin/my-branch'

                    // Push the changes to the remote repository
                    sh 'git push origin controller'
                }
            }
        }
    }
}

This pipeline checks out the controller branch, merges the my-branch into it, and then pushes the changes to the remote repository.