将本地 Docker 守护进程暴露给 minikube - Jenkins config.json: 系统找不到指定的路径
Exposing local Docker daemon to minikube - Jenkins config.json: The system cannot find the path specified
我是 运行 Jenkins Windows 10,安装了 Docker 工具箱和 minikube(也在 Windows 10)。
我可以使用这个 Powershell 命令 "map" 本地 Docker 图像到 minikube:minikube docker-env | Invoke-Expression
,一切都按预期工作。
我想使用 Jenkinsfile 做同样的事情
stage('Build1') {
steps {
powershell """
minikube docker-env | Invoke-Expression
"""
}
}
但是 Jenkins 正在错误的位置寻找 config.json 文件:
powershell.exe : *
At C:\Program Files (x86)\Jenkins\workspace\api-gateway_master@tmp\durable-355fdbbe\powershellWrapper.ps1:3 char:1
+ & powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Comm ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (* :String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
X Error getting config: CreateFile C:\Windows\system32\config\systemprofile\.minikube\profiles\minikube\config.json: The system cannot find the path specified.
配置文件实际上在用户配置文件路径中:C:\Users\username\.minikube\profiles\minikube\config.json
.
与 shell 命令相同的错误(Git for Windows)
stage('Build1') {
steps {
sh 'eval $(minikube docker-env)'
}
}
++ minikube docker-env
*
X Error getting config: CreateFile C:\Windows\system32\config\systemprofile\.minikube\profiles\minikube\config.json: The system cannot find the path specified.
还使用此开关创建了全新的 minikube:--insecure-registry windows 10 IP:5000
编辑:根据评论应用建议后:
在 Jenkins 中创建了环境变量:
MINIKUBE_HOME=C:\Users\user\.minikube
现在得到:
++ minikube docker-env
*
X Error getting host status
* Error: [MACHINE_DOES_NOT_EXIST] state: machine does not exist
* Suggestion: Run 'minikube delete' to delete the stale VM, or and ensure that minikube is running as the same user you are issuing this command with
minikube stop
,从 Virtual Box 中删除了 minikube VM,删除了文件夹 C:\Users\user\.minikube
,minikube start
,没有错误,但是当 运行 Jenkins 管道时,同样的错误。
怎么样,要使 'minikube' 集成在 Jenkins 管道内顺利进行,只需应用在上次错误输出中收到的提示。
Ensure that minikube is running as the same user you are issuing this
command with.
假设您的 Jenkins 主服务器 运行 作为 Windows 服务(默认情况下在本地系统帐户的上下文中),将其更改为专用的本地用户帐户(例如“.\user” ) - 与您创建的 minikube 实例相同。
另一种选择:将专用 credentials 与您的管道
结合使用
最终你可以切换到另一个设置(困难的方式):
Running Jenkins inside your (Minikube) Kubernetes cluster with Kubernetes plugin for Jenkins and Docker-outside-of-Docker groovy-based 管道(它重用主机 docker 守护进程 - 在你的例子中来自 Minikube)。
再也不用为 minikube 操心了
- 已卸载 minikube
- 已卸载 Docker 工具箱
- 已安装Docker Desktop
- 在Docker桌面启用Kubernetes(设置-Kubernetes-启用Kubernetes)
现在所有 docker 个图像都可用于 Kubernetes 和 Jenkins
我是 运行 Jenkins Windows 10,安装了 Docker 工具箱和 minikube(也在 Windows 10)。
我可以使用这个 Powershell 命令 "map" 本地 Docker 图像到 minikube:minikube docker-env | Invoke-Expression
,一切都按预期工作。
我想使用 Jenkinsfile 做同样的事情
stage('Build1') {
steps {
powershell """
minikube docker-env | Invoke-Expression
"""
}
}
但是 Jenkins 正在错误的位置寻找 config.json 文件:
powershell.exe : *
At C:\Program Files (x86)\Jenkins\workspace\api-gateway_master@tmp\durable-355fdbbe\powershellWrapper.ps1:3 char:1
+ & powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Comm ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (* :String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
X Error getting config: CreateFile C:\Windows\system32\config\systemprofile\.minikube\profiles\minikube\config.json: The system cannot find the path specified.
配置文件实际上在用户配置文件路径中:C:\Users\username\.minikube\profiles\minikube\config.json
.
与 shell 命令相同的错误(Git for Windows)
stage('Build1') {
steps {
sh 'eval $(minikube docker-env)'
}
}
++ minikube docker-env
*
X Error getting config: CreateFile C:\Windows\system32\config\systemprofile\.minikube\profiles\minikube\config.json: The system cannot find the path specified.
还使用此开关创建了全新的 minikube:--insecure-registry windows 10 IP:5000
编辑:根据评论应用建议后:
在 Jenkins 中创建了环境变量:
MINIKUBE_HOME=C:\Users\user\.minikube
现在得到:
++ minikube docker-env
*
X Error getting host status
* Error: [MACHINE_DOES_NOT_EXIST] state: machine does not exist
* Suggestion: Run 'minikube delete' to delete the stale VM, or and ensure that minikube is running as the same user you are issuing this command with
minikube stop
,从 Virtual Box 中删除了 minikube VM,删除了文件夹 C:\Users\user\.minikube
,minikube start
,没有错误,但是当 运行 Jenkins 管道时,同样的错误。
怎么样,要使 'minikube' 集成在 Jenkins 管道内顺利进行,只需应用在上次错误输出中收到的提示。
Ensure that minikube is running as the same user you are issuing this command with.
假设您的 Jenkins 主服务器 运行 作为 Windows 服务(默认情况下在本地系统帐户的上下文中),将其更改为专用的本地用户帐户(例如“.\user” ) - 与您创建的 minikube 实例相同。
另一种选择:将专用 credentials 与您的管道
结合使用最终你可以切换到另一个设置(困难的方式):
Running Jenkins inside your (Minikube) Kubernetes cluster with Kubernetes plugin for Jenkins and Docker-outside-of-Docker groovy-based 管道(它重用主机 docker 守护进程 - 在你的例子中来自 Minikube)。
再也不用为 minikube 操心了
- 已卸载 minikube
- 已卸载 Docker 工具箱
- 已安装Docker Desktop
- 在Docker桌面启用Kubernetes(设置-Kubernetes-启用Kubernetes)
现在所有 docker 个图像都可用于 Kubernetes 和 Jenkins