# Jenkins pipeline with GitLab

**URL:** <https://community.jenkins.io/t/jenkins-pipeline-with-gitlab/12882>\
**Category:** Using Jenkins\
**Created:** [February 28, 2024, 3:31pm UTC](https://community.jenkins.io/t/jenkins-pipeline-with-gitlab/12882 "2024-02-28T15:31:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sftiit](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/sftiit/32/2591_2.png) [@sftiit](https://community.jenkins.io/u/sftiit)\
**Post date:** [February 28, 2024, 3:31pm UTC](https://community.jenkins.io/t/jenkins-pipeline-with-gitlab/12882/1 "2024-02-28T15:31:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sftiit](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/sftiit/32/2591_2.png) [@sftiit](https://community.jenkins.io/u/sftiit)\
**Post date:** [March 2, 2024, 2:56pm UTC](https://community.jenkins.io/t/jenkins-pipeline-with-gitlab/12882/2 "2024-03-02T14:56:13Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![poddingue](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/poddingue/32/985_2.png) [@poddingue](https://community.jenkins.io/u/poddingue)\
**Post date:** [March 4, 2024, 9:17am UTC](https://community.jenkins.io/t/jenkins-pipeline-with-gitlab/12882/3 "2024-03-04T09:17:54Z")

</div>

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:

```auto
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.
