You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:GitHub App认证的Jenkins Maven构建执行release时认证失败

Jenkins中Maven Release结合GitHub App认证的推送问题解决

问题说明

初始代码检出通过GitHub App认证正常,但执行maven release:prepare release:perform时,Maven无法推送标签至GitHub,报错如下:

The git-push command failed.
Command output:
fatal: could not read Username for 'https://github.com': No such device or address

核心原因

Jenkins的GitHub App认证上下文仅覆盖初始代码检出环节,Maven Release插件执行git推送操作时,无法自动继承该认证信息,导致Git请求缺少凭据。

解决办法

  • 方法1:Maven命令直接传入凭据
    在Jenkins的Maven构建命令中,添加username和password参数,其中用户名填git,密码使用GitHub App生成的临时访问令牌:

    mvn release:prepare release:perform -Dusername=git -Dpassword=${GITHUB_APP_TOKEN}
    

    注:${GITHUB_APP_TOKEN}是Jenkins中GitHub App插件提供的临时令牌环境变量,需确保构建任务已配置该变量。

  • 方法2:预配置Git全局凭据
    在Maven命令前添加Git凭据配置步骤,让Git在推送时自动使用指定凭据:

    # 配置Git凭据存储
    git config --global credential.helper store
    # 写入GitHub App凭据
    echo "https://git:${GITHUB_APP_TOKEN}@github.com" > ~/.git-credentials
    # 执行Maven Release
    mvn release:prepare release:perform
    # 清理凭据文件(可选,避免残留)
    rm ~/.git-credentials
    
  • 方法3:在pom.xml中配置Release插件
    在项目的pom.xml中添加Maven Release插件的凭据配置,然后在Jenkins构建时传入令牌参数:

    <build>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-release-plugin</artifactId>
          <version>3.0.0</version>
          <configuration>
            <username>git</username>
            <password>${github.app.token}</password>
            <pushChanges>true</pushChanges>
          </configuration>
        </plugin>
      </plugins>
    </build>
    

    Jenkins构建命令:

    mvn release:prepare release:perform -Dgithub.app.token=${GITHUB_APP_TOKEN}
    

内容的提问来源于stack exchange,提问作者richard

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 12:02:52