【问题标题】:Jenkins release pipeline for GithubGithub 的 Jenkins 发布管道
【发布时间】:2022-11-24 14:53:47
【问题描述】:

我有一个 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 密钥,我该如何解决这个问题?

【问题讨论】:

    标签: github jenkins gradle release


    【解决方案1】:

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

    the documentation中所见,通过Jenkins Credentials plugin注册一个存储在Jenkins中的PAT(Personal Access Token)。
    然后使用 GitHub 插件将其转换为用户名/密码:

    转到全局配置并添加 GitHub Server Config。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-06
      • 2020-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-14
      相关资源
      最近更新 更多