java - Using maven to push an artifact to Gitlab
问题描述
I have a project that used to push artifacts out to Nexus, but we now need to change that to push it to Gitlab. When my CI/CD pipeline tries to do this deployment, it is getting an error of:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy
(default-deploy) on project foo: Failed to retrieve remote metadata foo:1.0.4-SNAPSHOT/maven-
metadata.xml: Could not transfer metadata foo:1.0.4-SNAPSHOT/maven-metadata.xml from/to foo-
snapshots (https://foo.nexus.com/repository/foo-snapshots/): Not authorized -> [Help 1]
Note that it is still trying to push it out to Nexus, instead of pushing it to Gitlab. How can I change my gitlab-ci.yml file, or my settings.xml, to have it push to Gitlab?
Here is my gitlab-ci.yml file:
stages:
- build
deploy:
stage: build
script:
- mvn clean deploy -e -B -U -Ddist=true -s settings.xml
Note that before when it was pushing it to Nexus, this was the first line of code in the script:
mvn-settings -u "${NEXUS_DEPLOY_USER}" -p "${NEXUS_DEPLOY_PASS}" --master-password "${NEXUS_MASTER_PASS}" -s foo-snapshots
. However I thought I can just override this by doing -s settings.xml
.
In this settings.xml is my gitlab token:
<server>
<id>foo</id>
<configuration>
<httpHeaders>
<property>
<name>Job-Token</name>
<value>${env.CI_JOB_TOKEN}</value>
And under that defines some distribution repositories:
<profiles>
<profile>
<id>gitlab-foo</id>
<repositories>
<repository>
<id>foo</id>
<url>https://gitlab.foo/api/v4/projects/700/packages/maven</url>
</repository>
</repositories>
<properties>
<distribution.repository.id>foo-snapshots</distribution.repository.id>
<url>https://gitlab.foo/api/v4/projects/700/packages/maven</url>
Also here is a relevant part of my pom.xml file:
<distributionManagement>
<repository>
<id>foo-snapshots</id>
<url>https://gitlab.foo/api/v4/projects/706/packages/maven</url>
</repository>
<snapshotRepository>
<id>foo-snapshots</id>
<url>https://gitlab.foo/api/v4/projects/706/packages/maven</url>
</snapshotRepository>
</distributionManagement>
解决方案
Make sure you've specified the deployment repository. Couple different ways you could do so:
推荐阅读
- php - PHP数组数组:在内部数组上推送项目的问题
- python - 如何在这个作业问题中获得正确的输出?
- php - Laravel:未定义属性:Illuminate\Database\Eloquent\Relations\HasMany::$game
- php - 如何为 WordPress 编写一个 webhook,允许我使用一个优惠券代码获得两个单独的折扣?
- javascript - 当 GPU 不可用时从 Aframe 重定向
- go - 如何在 https 中以生产模式运行 Beego 二进制文件?
- r - 如何绘制按月分组的每小时平均时间序列?
- robotframework - “应该是真的 ${list} == ['a', 'b', 'c']” 和 “应该是真的 $list == ['a', 'b', 'c' 有什么区别? ]”?
- javascript - 在提交时保持价值
- applescript - 如何在 Apple Mail Rule 上触发 AppleScript?