简体   繁体   中英

Github action push java artifact to github repo

I have a Github repo project using GitHub actions with a docker file used to build the SpringBoot Java project.
I want to download packages from the Github repo for custom artifacts from GitHub repo and also be able upload artifact to it.

So I followed the link Configuring Apache Maven for use with GitHub Packages by adding the section to a settings.xml file:

  <activeProfiles>
    <activeProfile>github</activeProfile>
  </activeProfiles>

  <profiles>
    <profile>
      <id>github</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 OWNER Apache Maven Packages</name>
          <url>https://maven.pkg.github.com/OWNER/REPOSITORY</url>
        </repository>
      </repositories>
    </profile>
  </profiles>

  <servers>
    <server>
      <id>github</id>
      <username>USERNAME</username>
      <password>${GITHUB_TOKEN}</password>
    </server>
  </servers>
</settings>

To publish the package from the dockerfile build I added the following to my pom.xml:

 <distributionManagement>
    <repository>
        <id>github</id>
        <name>GitHub OWNER Apache Maven Packages</name>
        <url>https://maven.pkg.github.com/OWNER/REPOSITORY</url>
    </repository>
</distributionManagement>

The following is the content of my dockerfile:

FROM adoptopenjdk/maven-openjdk10 as build
WORKDIR /app
ADD pom.xml /app/pom.xml
ADD src /app/src    
ADD settings.xml /root/.m2/settings.xml
RUN ["mvn", "clean", "install", "deploy"]

Is it possible to deploy from the dockerfile to Github repo? Somehow the deploy piece does not seem to work. I have tried few times but not sure what's wrong with my sections. Currently this is my error in my docker build:

Could not transfer metadata com.chg.sa:demo-sa-java-service:1.0-SNAPSHOT/maven-metadata.xml from/to github ( https://maven.pkg.github.com/OWNER/REPOSITORY ): Not authorized -> [Help 1]

I got the push working using Dockerfile building by passing in the github token as build arg and switching the owner and repo name to their values.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM