尝试使用github操作将代码部署到github包时出现错误代码400 [英] Error Code 400 when trying to (maven) deploy to github packages using github actions

查看:113
本文介绍了尝试使用github操作将代码部署到github包时出现错误代码400的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为使用github动作工作流将maven项目部署到github包的(貌似)简单的任务而苦苦挣扎.首先,这是我在maven deploy阶段遇到的错误:

I am struggling with the (seemingly) simple task of deploying a maven project to github packages using a github actions workflow. First of all, here's the error I am getting in the maven deploy phase:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project [project name]: Failed to retrieve remote metadata [groupId]:[artifactId]:1.0-SNAPSHOT/maven-metadata.xml: Could not transfer metadata [groupId]:[artifactId]:1.0-SNAPSHOT/maven-metadata.xml from/to github (https://maven.pkg.github.com/[username]/[repository]): Failed to transfer file https://maven.pkg.github.com/[username]/[repository]/[groupId as path]/[artifactId]/1.0-SNAPSHOT/maven-metadata.xml with status code 400 -> [Help 1]

(信息:我在[括号]中用通用术语替换了不必要的和/或私人的具体信息)

(Info: I replaced unneccessary and/or private concrete information with general terms in [brackets])

最有可能的是,实际的maven-metadata.xml文件不是问题所在,因为以前我已经看到状态为400的警告,例如无法上传校验和".我猜maven-metadata.xml只是它失败的第一个文件,但我可能完全不赞成这种假设,请告诉我是否如此.

Most likely, the actual maven-metadata.xml file is not the problem because I have already seen warnings like "could not upload checksum" with status 400 before. I guess that maven-metadata.xml is just the first file it fails on, but probably I am completely wrong with this assumption, please tell me if so.

可能最重要的文件是工作流yaml文件:

Probably the most important file is the workflow yaml file:

name: Deploy SNAPSHOT (develop)

on:
  push:
    branches:
      - develop

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v1
      - name: Set up JDK 11
        uses: actions/setup-java@v1
        with:
          java-version: 11
      - name: Maven Deploy
        env:
          GITHUB_USERNAME: x-access-token
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: mvn --settings settings.xml -B -e -Dmaven.wagon.http.pool=false clean deploy

同样非常重要:maven settings.xml文件:

Also quite important: the maven settings.xml file:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
    <activeProfiles>
        <activeProfile>github-packages</activeProfile>
    </activeProfiles>

    <profiles>
        <profile>
            <id>github-packages</id>
            <repositories>
                <repository>
                    <id>central</id>
                    <url>https://repo1.maven.org/maven2/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
                <repository>
                    <id>github</id>
                    <name>GitHub [username] Apache Maven Packages</name>
                    <url>https://maven.pkg.github.com/[username]</url>
                </repository>
            </repositories>
        </profile>
    </profiles>

    <servers>
        <server>
            <id>github</id>
            <username>${env.GITHUB_USERNAME}</username>
            <password>${env.GITHUB_TOKEN}</password>
        </server>
    </servers>
</settings>

(信息:括号中的值与以前一样)

(Info: same goes for values in brackets as before)

最后,我的maven项目的父pom.xml:

And lastly, the parent pom.xml of my maven project:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>[groupId]</groupId>
    <artifactId>[artifactId]</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <modules>
        [child modules]
    </modules>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <maven.compiler.release>11</maven.compiler.release>
    </properties>

    <dependencies>
        [my dependencies]
    </dependencies>

    <distributionManagement>
        <repository>
            <id>github</id>
            <name>GitHub [username] Apache Maven Packages</name>
            <url>https://maven.pkg.github.com/[username]/[repository]</url>
        </repository>
    </distributionManagement>


</project>

也许说GitHub存储库完全属于我也很重要,因此我应该对此拥有所有管理员权限.

Maybe it's also important to say that the GitHub repository belongs entirely to me and therefore I should have all admin rights on it.

到目前为止,我已经进行了一些研究,发现我的问题似乎并不罕见.尽管到目前为止,从我发现的所有解决方案中,没有一个起作用.

I have done some research by now and I found that my issue seems to be not uncommon. Although, from all solutions I've found so far, not one has worked.

  1. 官方GitHub文档设置工作流程

首先,我以本网站作为参考.

To start of, I used this site as my reference.

  1. 此StackOverflow问题

我主要坚持在这个问题及其答案中找到的所有建议.

I mostly stuck to all the advice I found in this question and in the answers to it.

  1. 关于nexus部署的另一个StackOverflow问题

该问题的可接受的答案提供了一个清单.尽管我无法验证所有内容,但我还是尝试检查所有要点是否对我有用.根据此清单,我没有发现任何问题.

The accepted answer of this question provides a checklist. I tried to check that all the bullet points work for me, although I wasn't able to validate everything. I did not find any issue based on this checklist.

  1. 在GitHub社区论坛上的问题

此问题中显示的错误看起来非常非常,就像我遇到的错误一样,但建议的解决方案仍然无法解决我的任何问题.

The error displayed in this question looks very much like the error I am getting, still the proposed solution did not fix anything for me.

  1. 此答案建议使用个人访问令牌代替GITHUB_TOKEN.我试过了,什么都没改变.

    This answer suggested using a personal access token instead of the GITHUB_TOKEN. I tried that and it changed nothing.

    如果有人可以向我展示我案件的确切问题,我当然会很高兴,但是并不需要那么具体.我正在尝试建立最基本的管道,并且我目前不希望做更多的事情,而不仅仅是将Maven快照存储库部署到github包(使用github动作).因此,如果有人可以向我展示如何正确地一般,那也很好.谢谢!

    Of course I'd be happy if someone can show me what the exact issue of my case is, but it does not need to be that specific. I am trying to set up the most basic pipeline possible and I currently don't want to do more than just deploy a maven snapshot repository to github packages (with github actions). So, if anyone can show me how to do this properly in general, that's also fine. Thanks!

    推荐答案

    我自己弄清楚了,但结果令人非常不满意.这里的主要问题是:

    I kinda figured it out myself, but the result is very dissatisfying. The main problem here is:

    注意:GitHub软件包不支持Apache Maven的SNAPSHOT版本.确保在〜/.m2/settings.xml文件中禁用SNAPHOT.

    Note: GitHub Packages does not support SNAPSHOT versions of Apache Maven. Make sure you disable SNAPHOT in your ~/.m2/settings.xml file.

    (来源)

    因此,似乎GitHub Packages不支持构建maven快照存储库,否则该存储库非常实用.我的计划是建立一个工作流,以在开发发生时在软件包注册表上部署新的SNAPSHOT. Maven快照存储库不需要唯一的版本号即可部署,这意味着我可以为每次推送构建一个新版本,但是实际的依赖版本保持不变.然后,每个人都可以轻松地尝试develop分支的最新状态,只需在其pom文件中包含固定的快照版本即可.

    So, it seems like GitHub Packages does not support the construct of maven snapshot repositories, which are otherwise very practical. My plan was to set up a workflow that deploys a new SNAPSHOT on the package registry when a push to develop happens. Maven snapshot repositories do not require unique version numbers for deploys, which means I could have built a new version for every push, but the actual dependency version stays fixed. Everyone could then easily try out the latest state of my develop branch, simply by including the fixed snapshot version in their pom files.

    现在,如何解决我的问题:

    Now, how to fix my issue:

    由于GitHub软件包不支持快照存储库,因此您必须从pom文件中project.version标记中的值中删除关键字"SNAPSHOT".基本上,您可以在其中放置所有其他版本说明,但是现在它是唯一的.但是,如果删除所有SNAPSHOT关键字,则工作流应将程序包正确部署到GitHub程序包注册表,至少对我有用.

    Because GitHub packages does not support snapshot repositories, you will have to remove the keyword "SNAPSHOT" from the value in the project.version tag in your pom file. Basically you can put every other version description there, but now it is unique. However if you remove all SNAPSHOT keywords, the workflow should properly deploy a package to the GitHub package registry, at least it worked for me.

    如果有人知道解决此SNAPSHOT问题的方法,请告诉我.否则,这是我到目前为止找到的唯一可行的解​​决方案.

    If anyone knows a way to "hack" around this SNAPSHOT issue, please tell me. Otherwise this is the only working solution I've found so far.

    这篇关于尝试使用github操作将代码部署到github包时出现错误代码400的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆