Merge branch B to Branch A

Merge branch B to Branch A



I m running a jenkins pipeline for my project.
Jenkins pulls the repository from gitlab and then runs my pipeline.
So the problem is that i want to merge B to A on gitlab when the pipeline runs successfully.
This is my Jenkinsfile which of course doesn't satisfy my need because it gives me the error



merge: test - not something we can merge


node
try
stage('Build')
def mavenHome = tool 'Maven'
checkout scm
sh "mvn clean install"

stage('SonarQube')
steps
sh "mvn clean verify sonar:sonar -Dsonar.branch.name="+ env.BRANCH_NAME



stage('Merge with Dev')

sh "git checkout dev"
sh "git pull gitlab dev"
sh "git merge test"





catch(error)
currentBuild.result = "FAILED"
mail to: 'mail here',
subject: "Failed Pipeline: $currentBuild.fullDisplayName",
body: "Something is wrong with $env.BUILD_URL"




I want to merge to be automatic, no merge request. Thank you





Try to do it from the command line on Jenkins machine, It looks like something is wrong with git not with Jenkins.
– Talha Junaid
Aug 31 at 20:32





how to do that exactly ? i mean i m on my jenkins machine now but i have no physical git repository of my project on it. i m using gitlab which is also on the same machine tho.
– Ziyed Becha
Aug 31 at 21:02





The repository is cloned onto the machine. You need to find where it is cloning. You can use sh 'pwd' in your script to find out an exact path where Jenkins has cloned your repository. On Linux usually Jenkins clone projects in /var/lib/jenkins/workspace directory
– Talha Junaid
Aug 31 at 21:07


sh 'pwd'


/var/lib/jenkins/workspace





The path is /var/lib/jenkins/workspace/projettest_issue5-ZP3ZOFFJDVDMG2NKVVH5JTLVMAZGUC2OAY2C7E255STSKQUIUKVA but this is not helping. i mean it's not a git repository and i can't access the git repositry of gitlab. What would be ideal if gitlab create a not bare repository on my server that i can access via jenkins and make my merges.
– Ziyed Becha
Aug 31 at 21:18



/var/lib/jenkins/workspace/projettest_issue5-ZP3ZOFFJDVDMG2NKVVH5JTLVMAZGUC2OAY2C7E255STSKQUIUKVA




1 Answer
1



I found a way to create a merge request when the pipeline is successful and that's by using API.Well, it doesn't do exactly do what i want (directly merge the branch when possible) but it's good enough for now (automatically create a merge request in gitlab).
This is the final stage in jenkinsfile


stage('Merge with Dev')


sh 'curl --request POST --header "PRIVATE-TOKEN: APITOKENHERE" "GITURL/api/v4/projects/PROJECTID/merge_requests?source_branch='+env.BRANCH_NAME+'&target_branch=A&title='+env.BRANCH_NAME+'ToA"'





Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ

Node.js puppeteer - Use values from array in a loop to cycle through pages