I have a Jenkins pipeline that utilizes unit tests in my project. I am using a MySQL database, but I encountered the following error:
mysql.connector.errors.DatabaseError: 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3306' (111)
I'm unsure how to configure my local host database on windows for this pipeline.
Please, could you help me?
Jenkins file
pipeline {
agent {
docker {
image 'python:3.8.7'
args '-u root'
}
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Install dependencies') {
steps {
sh 'pip install -r requirements.txt'
}
}
stage('Run tests') {
steps {
sh 'python -m unittest discover -s tests'
}
}
.....
db.py file (where the database configurations)
class Db:
def __init__(self):
# Connect to the MySQL database
load_dotenv()
host, user, password, database = os.getenv('HOST'), os.getenv('USER'), os.getenv('PASSWORD'), os.getenv(
'DATABASE')
self.mydb = mysql.connector.connect(
host=host,
user=user,
password=password,
database=database
)
lg.info('db connect great success')
self.cursor = self.mydb.cursor()
I tried to modify the my.ini file, restart the server, and build the Jenkins file that only connects to the MySQL server.