Error:-
[ERROR] Failed to execute goal:- Failed to deploy artifacts: Could not transfer artifact ExampleApp:jar:1.1 from/to gitlab-maven (https://gitlab-dedicated.com/api/v4/projects/1520/packages/maven): status code: 401, reason phrase: Unauthorized (401) ->
Scenario:-
Cause:-
Even after trying all the tokens not able to push to the gitlab package registry. It was because of how our settings.xml file has been written. If you just pushing the packages directly in package registry you need to follow the following gitlab documentation
https://docs.gitlab.com/ee/user/packages/maven_repository/
Solution :-
So the above documentation clearly gives the settings.xml as
<settings>
<servers>
<server>
<id>gitlab-maven</id>
<configuration>
<httpHeaders>
<property>
<name>REPLACE_WITH_NAME</name>
<value>REPLACE_WITH_TOKEN</value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
</settings>
However if you checkout the name it says REPLACE_WITH_NAME. So if you quickly going through the documentation you will understood it as the username of the token which you would have provided at the time of the deploy token creation. However thats where the fine prints come into the picture as
The <name>
field must be named to match the token you chose.
Even this might skip the checkpoint as name is mentioned but it specifically says that the name should be of deploy-token as
Token type | Name must be | Token |
---|---|---|
Personal access token | Private-Token | Paste token as-is, or define an environment variable to hold the token |
Deploy token | Deploy-Token | Paste token as-is, or define an environment variable to hold the token |
CI Job token | Job-Token | ${CI_JOB_TOKEN} |
which means you dont have to use the username instead use Deploy-Token. Now once i used the Deploy-Token username than my issue of the 401 unauthorized got resolved and i was able to upload the artifact into the gitlab registry. So finally my settings.xml file looks like this
<servers>
<server>
<id>gitlab-maven</id>
<configuration>
<httpHeaders>
<property>
<name>Deploy-Token</name>
<value><deploy-token></value>
</property>
</httpHeaders>
</configuration>
</server>
<profiles>
<profile>
<id>gitlab</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab-dedicated.com/api/v4/groups/56789/-/packages/maven</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
</settings>
0 comments:
Post a Comment