Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Authenticate bitbucket with Nexus Sonar Type.

Rodolfo Socas June 13, 2023

Hello, first of all, I apologize for the ignorance, I am new in the world of devops and I am learning to create pipelines, in my work we are doing proof of concept to use bitbucket-pipelines, the problem is that there is a repository that needs to connect to Nexus to host code from a library, and I created the pipeline, I added the variables authenticate access to Nexus, and still, the pipeline shows me the following error:

 

npm ERR! code E401
npm ERR! Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2023-06-14T05_13_35_966Z-debug.log
error Command failed with exit code 1.

1 answer

1 accepted

0 votes
Answer accepted
Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 14, 2023

Hello @Rodolfo Socas and welcome to the Atlassian Community!

From the error being returned, it seems the authentication failed because either the credentials were invalid or it was potentially not setup correctly.

According to Sonatypes docs on publishing NPM packages to Nexus, in order to configure npm to authenticate with your Nexus repo will you will need to provide the base64 encoded username:password in an attribute called _auth on the .npmrc file.

You should be able to do that by including the following commands at the beginning of your pipeline step script : 

npm config set registry="NEXUS_URL" #configure the registry to your nexus instance
npm config set _auth="$(echo -n "$NEXUS_USERNAME:$NEXUS_PASS" | base64)" #Configure the credentials of your Nexus repository and base64 encode them
npm config ls #confirm the configuration is correct
npm publish --registry NEXUS_URL #push to the Nexus registry

 The example above considers you have the Nexus credentials username and password configured as environment variables named NEXUS_USERNAME and NEXUS_PASS respectively. You can set those as secure repository variables in your bitbucket repo, so they are masked from the logs.

You can try the configuration above and let us know how it goes.

Thank you, @Rodolfo Socas !

Patrik S

Rodolfo Socas June 16, 2023

Thank you very much my friend, I appreciate it, it worked for me what I was trying to do. Greetings and success.

Rodolfo Socas June 16, 2023

Patrick, sorry to bother you, a strange thing happens to me, and is that my pipeline has two steps that are authenticated to nexus from bitbucket and write in nexus, that is, they create two folders and inside each one is saved a respective versions of each library, the problem is that the first step if saved, and the second one generates an error, I do not understand if the idea is that both write in nexus, what each one to different folders, I do not know what can happen so that one if it works and the other not, I leave the error that shows me the second step, maybe you can suggest me something according to your experience, I thank you in advance:

npm notice === Tarball Details ===
npm notice name: @chattigo/view-components
npm notice version: 1.4.10-SNAPSHOT-ae9a776a
npm notice package size: 180.1 kB
npm notice unpacked size: 800.9 kB
npm notice shasum: ea17c098f4f0813a7178ef91bcf6494ea5e34458
npm notice integrity: sha512-xwQXvw9h9Df3x[...]UDQ+pZxD8FcJw==
npm notice total files: 47
npm notice
npm ERR! code E404
npm ERR! 404 Not Found - PUT https://registry.yarnpkg.com/@chattigo%2fview-components - Not found
npm ERR! 404
npm ERR! 404 '@chattigo/view-components@1.4.10-SNAPSHOT-ae9a776a' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from an
npm ERR! 404 tarball, folder, http url, or git url.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2023-06-17T03_21_47_737Z-debug.log
error Command failed with exit code 1.

Patrik S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 19, 2023

Hey @Rodolfo Socas ,

I'm not very familiar with npm, but seems like this error is caused when you a trying to push to a scope that was either not created in the npm registry or you have not logged in with that user when doing the push. I found the following thread in StackOverflow that might be of help : 

Thank you, @Rodolfo Socas !

Patrik S

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events