简体   繁体   English

Jenkins Github 的发布管道

[英]Jenkins release pipeline for Github

I have a Jenkins pipeline job to make a release.我有一个 Jenkins 管道作业来发布。 It uses the Jenkin's Github plugin to checkout the project and make a build.它使用 Jenkin 的 Github 插件来检查项目并进行构建。

My simplified DSL is:我的简化 DSL 是:

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:我简化的“Jenkinsfile”就像:

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.但是,当它尝试执行release任务时,它会失败并出现以下异常。

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?我的理解是,当release任务运行时,它会尝试使用 SSH 连接到 Github,但我没有设置一个,因为我们不想在 Github 上维护 Jenkins 的“用户”。我如何在不设置的情况下解决这个问题在 Github 上增加 SSH 键?

You need to make sure you have proper credential set in the Jenkins system config page.您需要确保在 Jenkins 系统配置页面中设置了正确的凭据。

As seen in the documentation , register a PAT (Personal Access Token) stored in Jenkins through the Jenkins Credentials plugin .文档中所示,通过Jenkins Credentials 插件注册存储在 Jenkins 中的 PAT(个人访问令牌)。
Then convert it to a username/password using the GitHub plugin:然后使用 GitHub 插件将其转换为用户名/密码:

Go to the global configuration and add GitHub Server Config. Go 到全局配置,添加 GitHub Server Config。

在此处输入图像描述

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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