Exposing local Docker daemon to minikube – Jenkins config.json: The system cannot find the path specified

huangapple go评论92阅读模式
英文:

Exposing local Docker daemon to minikube - Jenkins config.json: The system cannot find the path specified

问题

我在Windows 10上运行Jenkins,安装了Docker工具箱和minikube(同样在Windows 10上)。

我可以使用以下PowerShell命令将本地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 delete后,从Virtual Box中删除minikube VM,删除文件夹C:\Users\user\.minikube,再次运行minikube start,没有错误,但在运行Jenkins管道时,仍然出现相同的错误。

英文:

I'm running Jenkins on Windows 10,installed Docker toolbox and minikube (also on Windows 10).

I can "map" local Docker images to minikube with this Powershell command: minikube docker-env | Invoke-Expression, everything works as expected.

I want to do the same using Jenkinsfile

stage('Build1') {
         steps {
            powershell """
            minikube docker-env | Invoke-Expression
            """
           
         }
      }

But Jenkins is looking for config.json file in wrong location:

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.

config file is actually in userprofile path:C:\Users\username\.minikube\profiles\minikube\config.json.

Same error with shell command (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.

Also created brad new minikube with this switch:--insecure-registry windows 10 IP:5000

EDIT:After applying suggestion as per comment:

Created environment variable in Jenkins:

MINIKUBE_HOME=C:\Users\user\.minikube

Now getting:

++ 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

Did minikube stop, deleted minikube VM from Virtual Box,deleted folder C:\Users\user\.minikube, minikube start, no errors, but when running Jenkins pipeline, same error.

答案1

得分: 2

如何让Jenkins流水线中的'minikube'集成更顺畅,只需应用上次错误输出中收到的提示。

确保minikube正在与发出此命令的相同用户一起运行。

假设您的Jenkins主服务器以Windows服务形式运行(默认情况下以本地系统帐户的上下文运行),请将其更改为专用的本地用户帐户(例如".\user") - 与您创建minikube实例的相同用户。

另一种选择是在您的流水线中使用专用的凭据

最终,您可以切换到另一种设置(较困难的方式):

在(Minikube)Kubernetes集群中运行Jenkins,使用Jenkins的Kubernetes插件Docker外部Docker基于Groovy的流水线(它会重用主机上的Docker守护程序 - 在您的情况下来自Minikube)。

英文:

How about this, to make the 'minikube' integration smooth inside the Jenkins pipeline just apply the hint received on last error output.

> Ensure that minikube is running as the same user you are issuing this
> command with.

Assuming your Jenkins master server is running as a Windows Service (in context of Local System account by default), change it to the dedicated local user account (e.g ".\user") - the same you have created your minikube instance with.

Another option: use dedicated credentials with your Pipeline

Eventually you can switch into another setup (hard way):<br><br>
Running Jenkins inside your (Minikube) Kubernetes cluster with Kubernetes plugin for Jenkins and Docker-outside-of-Docker groovy-based pipeline (it reuses host docker daemon - in your case from Minikube).

答案2

得分: 0

不再需要操作minikube了

  • 卸载了minikube
  • 卸载了Docker Toolbox
  • 安装了Docker Desktop
  • 在Docker Desktop中启用了Kubernetes(设置-Kubernetes-启用Kubernetes)

现在所有的Docker镜像都可以在Kubernetes和Jenkins中使用

英文:

No need to mess with minikube anymore

  • uninstalled minikube
  • uninstalled Docker Toolbox
  • installed Docker Desktop
  • On Docker desktop enabled Kubernetes (Settings-Kubernetes-enable Kubernetes)

Now all docker images are available to Kubernetes and Jenkins

huangapple
  • 本文由 发表于 2020年1月6日 20:12:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/59611895.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定