繁体   English   中英

Jenkins Github 的发布管道

[英]Jenkins release pipeline for Github

我有一个 Jenkins 管道作业来发布。 它使用 Jenkin 的 Github 插件来检查项目并进行构建。

我的简化 DSL 是:

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

我简化的“Jenkinsfile”就像:

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

但是,当它尝试执行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)

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

您需要确保在 Jenkins 系统配置页面中设置了正确的凭据。

文档中所示,通过Jenkins Credentials 插件注册存储在 Jenkins 中的 PAT(个人访问令牌)。
然后使用 GitHub 插件将其转换为用户名/密码:

Go 到全局配置,添加 GitHub Server Config。

在此处输入图像描述

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