そういうのがいいブログ

SIerで働く30代サラリーマンSEがインフラエンジニアに憧れてLinux・クラウド・AWSの勉強をするブログ

GitLabエラー「fatal: detected dubious ownership in repository at」の対処方法

※[PR]当ブログの記事の中にはプロモーションが含まれています。

・GitLabでエラー「fatal: detected dubious ownership in repository at ディレクトリ名」が出たときの対処方法を知りたい。

こういった疑問に答えます。

本記事の内容

  1. GitLabでエラー「fatal: detected dubious ownership in repository at ディレクトリ名」が出たときの対処方法

サトナカ (@souiunogaii)

この記事を書いている私は、某SIerに勤務しながら、
WEB系エンジニア・インフラエンジニアに憧れて、プログラミングおよびインフラ技術の勉強をしています。

こういった私が、解説していきます。

私が実機で試したコマンドや画像を載せて書いています。
記事の信頼性担保に繋がると思います。

GitLabでエラー「fatal: detected dubious ownership in repository at ディレクトリ名」が出たときの対処方法

発生事象

JenkinsからGitLabのpullを実行しようとしたら、下記エラーが発生しました。

ユーザーsatonakaが実行
Running as SYSTEM
sv-neptune.planet.space.com でビルドします。 (SV-NEPTUNE) ワークスペース: /home/jenkins/workspace/MyPortalSite-release
No emails were triggered.
[MyPortalSite-release] $ /bin/sh -xe /tmp/jenkins17689442684270726618.sh
+ cd /home/www/html/myportalsite
+ git stash
fatal: detected dubious ownership in repository at '/home/www/html/myportalsite'
To add an exception for this directory, call:

    git config --global --add safe.directory /home/www/html/myportalsite
Build step 'シェルの実行' marked build as failure
Email was triggered for: Failure - Any
Sending email for trigger: Failure - Any
Sending email to: satonaka@space.com
Finished: FAILURE

サーバー上でコマンド実行しても同じ結果

[satonaka@sv-neptune myportalsite]$ su jenkins
パスワード:
[jenkins@sv-neptune myportalsite]$
[jenkins@sv-neptune myportalsite]$
[jenkins@sv-neptune myportalsite]$
[jenkins@sv-neptune myportalsite]$
[jenkins@sv-neptune myportalsite]$ git stash
fatal: detected dubious ownership in repository at '/home/www/html/myportalsite'
To add an exception for this directory, call:

        git config --global --add safe.directory /home/www/html/myportalsite

対処方法

指示された通りのコマンドを実行してみます。

git config --global --add safe.directory ディレクトリ名
[jenkins@sv-neptune myportalsite]$ git config --global --add safe.directory /home/www/html/myportalsite

再度確認するとエラー解消しました

[jenkins@sv-neptune myportalsite]$ git stash
No local changes to save
ユーザーsatonakaが実行
Running as SYSTEM
sv-neptune.planet.space.com でビルドします。 (SV-NEPTUNE) ワークスペース: /home/jenkins/workspace/MyPortalSite-release
No emails were triggered.
[MyPortalSite-release] $ /bin/sh -xe /tmp/jenkins4485644451571051633.sh
+ cd /home/www/html/myportalsite
+ git stash
No local changes to save
+ git pull origin master
From gitlab.sv-mars.planet.space.com:neptune-group01/myportalsite
 * branch            master     -> FETCH_HEAD
   7aa2f3d..dde8d9d  master     -> origin/master
Updating 7aa2f3d..dde8d9d
Fast-forward
 certifi.php | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
Email was triggered for: Success
Sending email for trigger: Success
Sending email to: satonaka@space.com
Finished: SUCCESS