Using git publisher from a Jenkinsfile pipeline?

12,076 views
Skip to first unread message

Mark Waite

unread,
Jun 19, 2016, 11:02:10 AM6/19/16
to Jenkins Users
I've been creating Jenkins jobs as tests of various bug fixes and storing them in a git repository.  Currently, the Jenkins jobs include the definition of the verification steps to confirm the bug is fixed.

The pipeline file seems like a better way to check that the problem is fixed, since the checks for successful job completion can be done in groovy.

One of the bugs I need to check needs to use the git publisher to push a commit back to the originating repository and branch.  In the snippet generator I can see an entry for "publishHTML", but I don't see any entry that would let me use the git publisher to push changes.  A google search also did not show any obvious hints of ways I could use the git publisher.

Are there examples that use the git publisher from a pipeline script?

Thanks,
Mark Waite

Mark Waite

unread,
Jun 19, 2016, 11:30:43 AM6/19/16
to Jenkins Users
I found the answer.  Sorry to bother the list.

Git publisher is not yet supported with pipeline (see https://issues.jenkins-ci.org/browse/JENKINS-28335)


Mark Waite

Random Guy

unread,
Aug 26, 2016, 8:02:40 PM8/26/16
to Jenkins Users
I tried withCredentials() method...  its giving an error.. NoSuchMethodError...

java.lang.NoSuchMethodError: No such DSL method 'withCredentials' found

 Here is how my method look

withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'myid', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {

           sh("git tag -a ${TAG_NAME}")
           sh('git push https://${USERNAME}:${PASSWORD}@game-of-life --tags')
}

any idea?

Andrey Makeev

unread,
Sep 20, 2016, 4:28:51 AM9/20/16
to Jenkins Users

I want to share my Jenkins Pipeline setup and my solution to publish changes/tags to git repo via SSH (While Git Publish Support is under development). Please check it out for more info, any improvement ideas are welcome.

In short you just add file *git_push_ssh.groovy* to your project and call method pushSSH() from Jenkinsfile like this:

    env.BRANCH_NAME = "mycoolbranch"// BRANCH_NAME is predefined in multibranch pipeline job
    env
.J_GIT_CONFIG = "true"
    env
.J_USERNAME = "Jenkins CI"
    env
.J_EMAIL = "jenki...@example.com"
    env
.J_CREDS_IDS = '02aa92ec-593e-4a90-ac85-3f43a06cfae3' // Use credentials id from Jenkins
   
def gitLib = load "git_push_ssh.groovy"
   
...
    gitLib
.pushSSH(commitMsg: "Jenkins build #${env.BUILD_NUMBER}", tagName: "build-${env.BUILD_NUMBER}", files: "changelog.txt someotherfile.txt");



суббота, 27 августа 2016 г., 4:02:40 UTC+4 пользователь Random Guy написал:

Eduardo Aparicio Cardenes

unread,
Apr 4, 2017, 4:05:49 AM4/4/17
to Jenkins Users
This is really cool guys. 

I was wondering why

checkout scm

it didn't enable git command to avoid create sh command, but I guess this is in progress. it will be good if you can share as troubleshooting in pipelines plugin because the integration with Git is a little unclear for a newbie like me
Reply all
Reply to author
Forward
0 new messages