首页 > 解决方案 > 在 gitlab 中发布 Maven

问题描述

我们正在尝试使用 maven 执行 maven 版本。我们使用gitlab作为我们的 CI 工具。问题是当我们尝试执行 maven 发布时,maven 无法将pom.xml更新到下一次迭代。

谷歌无法回答我的问题。我尝试过的是:

下面是我的 .gitlab-ci.yml 文件-

    Maven_Release:
    stage: Maven_Release
    image: maven_Build:Latest
    script:
    - git config --global user.name "username"
    - git config --global user.email "Email"
    - git checkout -f master
    - git remote set-url origin https://gitlab.com/test1/project/${CI_PROJECT_NAME}.git
    - mkdir -p ~/.ssh
    - echo "$SSH_PRIVATE_KEY" > /root/.ssh/id_rsa
    - ssh-keyscan -p 10022 gitlab.com >> ~/.ssh/known_hosts
    - mvn -B -s settings.xml -DdeployAtEnd=false -Dmaven.site.deploy.skip=true -Dresume=false -DautoVersionSubmodules=true -DdryRun=false -Djsse.enableSNIExtension=false -Dmaven.test.skip=true -DreleaseVersion=1.0.0 -DdevelopmentVersion=1.0.1 -DskipITs -DscmCommentPrefix="[ci skip]" release:prepare release:perform
    when: manual
    only:
    - master

我尝试运行此作业,它能够部署,标记版本,但由于以下错误,它无法将 pom.xml 版本更改为下一次迭代,

    [INFO] Checking in modified POMs...
    [INFO] commit done: [ci skip]prepare release REL_xxxxx
    [INFO] push changes to remote... refs/heads/master:refs/heads/master
    [INFO] fetch url: https:/usrname:password@gitlabt.com/test/project/projectname.git
    [INFO] push url: https:/usrname:password@gitlabt.com/test/project/projectname.git
    [INFO] REJECTED_OTHER_REASON - RemoteRefUpdate[remoteName=refs/heads/master, REJECTED_OTHER_REASON, (null)...xx3xxx9c7cdc6dxx, fastForward, srcRef=refs/heads/master, message="pre-receive hook declined"]
    [INFO] Tagging release with the label REL_xxxxx...
    [INFO] push tag [REL_xxxxxx] to remote...
    [INFO] fetch url: https:/usrname:password@gitlabt.com/test/project/projectname.git
    [INFO] push url: https:/usrname:password@gitlabt.com/test/project/projectname.git
    [INFO] OK - RemoteRefUpdate[remoteName=refs/tags/REL_xxxxx, OK, (null)...c5ce4d1fdf5f0a9415d9f02a48aab4f536eab52c, fastForward, srcRef=refs/tags/REL_xxxxx, message=null]
    [INFO] Transforming 'project name'...
    [INFO] Transforming 'Rproject'...
    [INFO] Transforming 'project'...
    [INFO]   Updating project name to xxx-SNAPSHOT
    [INFO] Not removing release POMs
    [INFO] Checking in modified POMs...
    [INFO] commit done: [ci skip]prepare for next development iteration
    [INFO] push changes to remote... refs/heads/master:refs/heads/master
    [INFO] fetch url: https:/usrname:password@gitlabt.com/test/project/projectname.git
    [INFO] push url: https:/usrname:password@gitlabt.com/test/project/projectname.git
    [INFO] REJECTED_OTHER_REASON - RemoteRefUpdate[remoteName=refs/heads/master, REJECTED_OTHER_REASON, (null)...1xxxxx541baf208dxxxd, fastForward, srcRef=refs/heads/master, message="pre-receive hook declined"]
    [INFO] Release preparation complete.
    [INFO] 
    [INFO] --- maven-release-plugin:2.5.1:perform (default-cli) @ mobile-interface-parent ---

标签: gitmavengitlab-cimaven-release-plugin

解决方案


你开始:

mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" > /root/.ssh/id_rsa
ssh-keyscan -p 10022 gitlab.com >> ~/.ssh/known_hosts

这非常适合提供具有开发人员权限的正确 SSH 密钥以推回 GitLab 存储库(或具有相同权限的部署密钥)

但是……你不使用它!

git remote set-url origin https://gitlab.com/test1/project/${CI_PROJECT_NAME}.git

这是一个 https URL,而不是 SSH URL(ssh://git@gitlabt.com/test/project/projectname.gitgit@gitlabt.com:test/project/projectname.git)。

(我假设gitlabt.com是一个错字,你实际上看到了gitlab.com

任何 https URL 都将使用git config credential.helper具有为该 URL 存储的凭据的 。这些凭据可能不是允许mvn release:prepare推回 GitLab 存储库的正确凭据。

检查您的pom.xml: 它可以将 URLmvn release与该scm部分一起提供:

<scm>
  <developerConnection>scm:git:ssh://git@gitlab.com:/test1/project/${CI_PROJECT_NAME}.git</developerConnection>
</scm> 

developerConnection如果您希望自己~/.ssh/id_rsa真正有用,请确保其中包含 SSH URL。


OP pandey在评论中确认:

我给出了不同的电子邮件 ID。但是 maven 无法找出确切的问题并给出了 put 作为“ REJECTED_OTHER_REASON - RemoteRefUpdate”。
因此,我尝试提供其他电子邮件 ID,并且效果很好。

此外,在 GitLab 我尝试修改 push rules :::: project settings>Repository>push Rules
如果我们需要使用不同的电子邮件地址,我也删除了提交者限制。


推荐阅读