简体   繁体   中英

Jenkins release pipeline for Github

I have a Jenkins pipeline job to make a release. It uses the Jenkin's Github plugin to checkout the project and make a build.

My simplified DSL is:

multibranchPipelineJob('Release') {
    ...
    branchSources {
        branchSource {
            source {
                github {
                    id('AAA')
                    repoOwner('BBB')
                    repository('CCC')
                    credentialsId('github-credentials')
                    repositoryUrl('https://github.com/BBB/CCC')
                    configuredByUrl(false)
                }
            }
          ...
        }
    }
    ...
}

and my simplified 'Jenkinsfile' is like:

pipeline {
    agent any
    stages {
        stage('Build & Release') {
            steps {
                sh "./gradlew clean build release"
            }
        }
    }
}

But, when it tries to execute the release task, it fails with the following exception.

Caused by: org.eclipse.jgit.errors.TransportException: https://github.com/BBB/CCC.git: Authentication is required but no CredentialsProvider has been registered
    at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:531)
    at org.eclipse.jgit.transport.TransportHttp.openPush(TransportHttp.java:434)
    at org.eclipse.jgit.transport.PushProcess.execute(PushProcess.java:127)
    at org.eclipse.jgit.transport.Transport.push(Transport.java:1335)
    at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:137)

My understanding is that when release task is run, it tries to connect using SSH to Github, but I haven't setup one as we don't want to maintain a 'user' for Jenkins on Github. How can I resolve this without setting up SSH keys on Github?

You need to make sure you have proper credential set in the Jenkins system config page.

As seen in the documentation , register a PAT (Personal Access Token) stored in Jenkins through the Jenkins Credentials plugin .
Then convert it to a username/password using the GitHub plugin:

Go to the global configuration and add GitHub Server Config.

在此处输入图像描述

Go to Advanced -> Manage Additional GitHub Actions -> Convert Login and Password to token

https://github.com/jenkinsci/github-plugin/blob/master/docs/images/manage-token.png

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM