![](/img/trans.png)
[英]Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'node'@'127.0.0.1
[英]Access denied for user ''@'127.0.0.1' (using password: NO) running node app in Jenkins pipeline
我正在嘗試為我的 Nodejs 應用程序設置一個 Jenkins 管道。 我有一個 Ubuntu Docker 圖像,其中 Mariadb 工作正常,數據庫啟動,我可以從 Jenkinsfile 連接並執行 SQL 腳本。 Jenkins 以 root 用戶身份啟動 Docker 映像。 節點應用程序正在使用 Mariadb 連接器(包 mariadb)
在 Jenkins 之外,節點應用程序能夠連接到本地 MariaDB(用於測試)或遠程 MariaDB(已部署的應用程序)......那里的連接沒有問題。 在本地集成測試期間也沒有問題。
當我嘗試通過 Jenkins 運行測試時,節點應用程序嘗試創建與數據庫的連接時出現此錯誤: SequelizeAccessDeniedError: (conn=14, no: 1045, SQLState: 28000) Access denied for user ''@'127.0.0.1' (using password: NO)
在 Jenkinsfile 中,我正在檢查 Docker 的 MariaDB 數據庫中 testuser 的創建,用戶已在其中成功創建。
我在連接之前將連接詳細信息打印到控制台,一切都是正確的……那么為什么 MariaDB 連接器會嘗試連接默認用戶?
編輯:我也嘗試在數據庫 class 構造函數中設置 socketPath,但它得到相同的錯誤。
Dockerfile:
from mariadb:10.7.7-focal
# Install additional packages
RUN set -eux; \
apt-get update; \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
curl \
wget \
npm \
unzip \
iceweasel \
vim \
&& wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
&& apt-get install -y --no-install-recommends ./google-chrome-stable_current_amd64.deb
# Install NodeJs 18.x
RUN curl -sL https://deb.nodesource.com/setup_18.x -o nodesource_setup.sh \
&& bash nodesource_setup.sh \
&& apt-get install -y --no-install-recommends nodejs
Jenkins:
stage ('Setup test data in database')
{
steps
{
echo "*** Setting up test data in database ***"
sh "set"
sh "service mariadb start -v --skip-name-resolve"
sh "echo password | mariadb -u root -p -e \"CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'password';\""
sh "echo password | mariadb -u root -p -e \"CREATE USER 'testuser'@'127.0.0.1' IDENTIFIED BY 'password';\""
sh "echo password | mariadb -u root -p -e \"GRANT ALL PRIVILEGES ON *.* TO 'testuser'@'127.0.0.1';\""
sh "echo password | mariadb -u root -p -e \"GRANT ALL PRIVILEGES ON *.* TO 'testuser'@'localhost';\""
sh "echo password | mariadb -u root -p -e \"FLUSH PRIVILEGES;\""
sh "echo password | mariadb -u root -p -e \"SELECT user,authentication_string,plugin,host,password FROM mysql.user;\""
sh "echo password | mariadb -u root -p -e \"SOURCE database/create.sql\""
}
}
// End SETUP DATABASE
stage ('Fetch integration test drivers')
{
steps
{
echo "*** Fetching integration test drivers ***"
sh "google-chrome --version"
sh script:'''
mkdir ./tests/integration/drivers
wget https://github.com/mozilla/geckodriver/releases/download/v0.32.0/geckodriver-v0.32.0-linux64.tar.gz
tar -x geckodriver -zf geckodriver-v0.32.0-linux64.tar.gz -O > tests/integration/drivers/geckodriver && chmod +x ./tests/integration/drivers/geckodriver
wget https://chromedriver.storage.googleapis.com/108.0.5359.71/chromedriver_linux64.zip
unzip chromedriver_linux64.zip && chmod +x chromedriver && mv chromedriver ./tests/integration/drivers
rm geckodriver-v0.32.0-linux64.tar.gz && rm chromedriver_linux64.zip
'''
}
}
// End CLONING
stage ('Run NPM install')
{
steps
{
echo "*** Running npm install ***"
sh "npm install"
}
}
// End NPM INSTALL
stage ('Running Integration Tests')
{
steps
{
echo "*** Starting Integration Tests ***"
sh '(npm run dev-api & npm run dev-frontend-instance1 & npm run dev-frontend-instance2) && npm run test-integration'
}
}
節點應用數據庫 class 構造函數:
class Database {
private static _instances: { instance1: Database | undefined, instance2: Database | undefined } = {
instance1: undefined,
instance2: undefined
};
private _connectionDetails = {
host: process.env.API_IP ? process.env.API_IP : "localhost",
user: process.env.DATABASE_USER ? process.env.DATABASE_USER : "testuser",
password: process.env.DATABASE_PASSWORD ? process.env.DATABASE_PASSWORD : "password",
port: 3306,
database: ""
};
private _connection: Promise<mariadb.Connection>;
private _frontendHostname: string;
constructor(databaseName: string) {
this._connectionDetails.database = databaseName;
console.log("CONNECTION DETAILS: ", this._connectionDetails);
this._connection = mariadb.createConnection(this._connectionDetails);
this._frontendHostname = databaseName == "instance1" ? "https://url1" : "https://url2";
if (process.env.API_IP == "localhost") {
this._frontendHostname = "https://localhost:8080";
}
}
Jenkins 中的 Output:
CONNECTION DETAILS: {
host: 'localhost',
user: 'testuser',
password: 'password',
port: 3306,
database: 'instance1'
}
SequelizeAccessDeniedError: (conn=14, no: 1045, SQLState: 28000) Access denied for user ''@'127.0.0.1' (using password: NO)
我最終創建了它正在尋找的用戶,現在可以使用了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.