Progger Progger - 1 year ago 404
Git Question

Is it possible to Git merge / push using Jenkins pipeline

I am trying to create a Jenkins workflow using a Jenkinsfile. All I want it to do is monitor the 'develop' branch for changes. When a change occurs, I want it to git tag and merge to master. I am using the GitSCM Step but the only thing that it appears to support is git clone. I don't want to have to shell out to do the tag / merge but I see no way around it. Does anyone know if this is possible? I am using BitBucket (on-prem) for my Git server.

Answer Source

It is not possible at the moment because GitPublisher plugin, the plugin previously responsible for tagging/merging/pushing in freestyle jobs, has not been updated to be compatible with Jenkins pipelines. You can follow that issue on both the pipeline plugins compatibility page and the dedicated GitPublisher Jira issue.

So it seems the only option you have is to actually shell out your tag/merge commands... However, note that you can still benefit from some Jenkins built-in capabilities such as the use of credentials for your Git repo, which make it pretty straightforward to then tag / merge following your needs.

Example check-out :

git url: "ssh://jenkins@your-git-repo:12345/your-git-project.git",
    credentialsId: 'jenkins_ssh_key',
    branch: develop

Then the tag / merge / push will be pretty straightforward :

sh 'git tag -a tagName -m "Your tag comment"'
sh 'git merge develop'
sh 'git commit -am "Merged develop branch to master'
sh "git push origin master"

I hope that one day GitPublisher will be released in a pipeline-compatible version, but for now this workaround should do.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download