Course: Jenkins Pipelines
Video: Unit Testing and Analyze JUnit Reports
MongoDB Information:
The MongoDB username and password can be found in the video starting at minute
4:25.
The database connection string is: mongodb+srv://supercluster.d83jj.mongodb.net/superData
I omit the password, which may be your problem. I’m supporting multiple labs using this database, so I’m very confident that using those credentials plus the password gives you read/only access to that database; it works.
Please try these credentials using the nodejs app from the command line (export the 3 variables before you run npm test); they should work. Once you’ve verified that they work, we can start to figure out why your Jenkins pipeline is failing.
Thank you for the feedback. The error was in the URI declaration. It wasn’t being correctly interpreted with double quotes after being retrieved by the npm test command.
Video: Unit Testing and Analyze JUnit Reports
even though running superpassword as password and superuser as username through environments variables still i’m facing this issue
Which lab from that course? If I recall correctly, he initially has you run just the nodejs application locally, w/o Jenkins. Is this what you’re doing here, or what else? If it’s in Jenkins, you’ll need to somehow pass the mongo parameters via Jenkins’ what are you doing in that case?
Sorry it took a while. Part of the problem here is that you are not supplying the info needed to speed your support:
You should include your work, such as whatever you’re using for your jenkins file, NOT AS AN IMAGE, but as a code block, as I’ve done here above.
You should detail the steps you did. This is particularly true when you’re doing a follow along, because I cannot tell what you did, what you listened to, or what failed.
If you’ll do that, you’ll get MUCH faster service from us. Please do that!
In my Jenkins, I initially had the config slightly off, and at run time the pipeline did not find the credential. I deleted it and recreated it, and it worked. You might want to try this as well.
Mr. Rob, I did what you mentioned above and it still gives me “bad auth: authentication failed”. I deleted the credentials and created them again.
I tested via CLI by exporting the variables outside the Jenkins environment, i.e. on my local machine, and I got the same error. For me, either the password does not match or there is some origin locking on the server/database.
By the way, I created a mongo database on my Atlas to test the communication from here to my environment and it works perfectly.
username and password can be found in the document:
Just to make sure it’s really your access to the Atlas instance we use for this course, please try the following modified pipeline I just tried locally:
pipeline {
agent any
tools { nodejs 'NodeJS 16.20.2' }
environment {
MONGO_URI = "mongodb+srv://supercluster.d83jj.mongodb.net/superData"
}
stages {
stage('Install Dependencies') {
steps {
sh 'npm install --no-audit'
}
}
stage('Run Unit Tests') {
// some block
steps {
withCredentials([usernamePassword(credentialsId: 'mongo-db-credentials', passwordVariable: 'MONGO_PASSWORD', usernameVariable: 'MONGO_USERNAME')]) {
// sh 'npm test'
sh 'echo $MONGO_PASSWORD'
sh 'echo $MONGO_USERNAME'
}
}
}
}
}
This worked for me as well, with this from the output:
[Pipeline] { (Run Unit Tests)
[Pipeline] tool
[Pipeline] envVarsForTool
[Pipeline] withEnv
[Pipeline] {
[Pipeline] withCredentials
Masking supported pattern matches of $MONGO_PASSWORD
[Pipeline] {
[Pipeline] sh
+ echo ****
****
[Pipeline] sh
+ echo superuser
superuser
OK, that looks OK. Assuming the password is OK, you do appear to have a valid credential.
I installed mongosh on my virtual. This works:
ubuntu@jenkins:~$ mongosh "mongodb+srv://supercluster.d83jj.mongodb.net/superData" -u superuser
Enter password: *************
Current Mongosh Log ID: 67eeeb7c77dba0315d300588
Connecting to: mongodb+srv://<credentials>@supercluster.d83jj.mongodb.net/superData?appName=mongosh+2.4.2
Using MongoDB: 8.0.6
Using Mongosh: 2.4.2
For mongosh info see: https://www.mongodb.com/docs/mongodb-shell/
Atlas atlas-11b0vt-shard-0 [primary] superData> db.planets.find()
[
{
_id: ObjectId('64de122465ba6ca132e2d047'),
id: 4,
name: 'Mars',
image: 'https://gitlab.com/sidd-harth/solar-system/-/raw/main/images/mars.png',
velocity: '24',
distance: '227',
description: 'Mars is the fourth planet from the Sun and is the second smallest planet in the solar system. Named after the Roman god of war, Mars is also often described as the “Red Planet” due to its reddish appearance. Mars is a terrestrial planet with a thin atmosphere composed primarily of carbon dioxide. Mars has two known moons, Phobos and Deimos (fear and dread, after attendants of Ares, the Greek god of war, equivalent to the Roman Mars). Searches for more satellites have been unsuccessful, putting the maximum radius of any other satellites at 90 m (100 yd).'
},
...
See if this fails for you, in which case for some reason, you can’t use the DB. Otherwise, it’s some other config issue we haven’t covered yet.