3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

macOSにHomebrewで導入したJenkinsでdockerコマンドを使うための設定

Last updated at Posted at 2022-03-07

はじめに

macOSにHomebrewでJenkinsを導入し、Jenkins pipelineでdockerコマンドを使用すると、以下のエラーが出てdockerコマンドが実行できませんでした。当記事では、この事象を解決する設定について記載します。

# エラー内容
docker: command not found

前提環境

  • マシン:MacBook Pro (14インチ, 2021)(M1 Max, メモリ64GBモデル)
  • OS:macOS Monterey 12.0.1
  • Jenkins 2.334(Homebrewで導入)
  • Docker CLIはHomebrewで導入済み

設定内容

Homebrewで導入したJenkinsで実行されるジョブの環境変数PATHは、macOSで使用しているユーザのPATHと異なります。そのため、dockerコマンドの場所をJenkins用に設定する必要があります。

まず以下のコマンドを実行して、dockerコマンドの場所を確認します。

which docker

次に、Jenkinsに対して設定していきます。

Apple Silicon(M1以降)のMacでは、Homebrewで導入したJenkinsは/opt/homebrew/Cellar/jenkins/<バージョン番号>に配置されますが、このディレクトリにあるhomebrew.mxcl.jenkins.plistファイルを編集し、環境変数PATHを設定します。

私の環境では、dockerコマンドは/opt/homebrew/binにあるので、以下のように設定します。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    (中略)
	<key>EnvironmentVariables</key>
	<dict>
		<key>PATH</key>
		<string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin</string>
	</dict>
</dict>
</plist>

上記の通りファイルを編集・保存した後、Jenkinsを再起動します。

brew services restart jenkins

以上です。

3
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?