部署jenkins在k8s上
pipeline内容:

pipeline {
    agent {
        docker { image 'node:7-alpine' }
    }
    stages {
        stage('Test') {
            steps {
                sh 'node --version'
            }
        }
    }
}

报错:

+ docker inspect -f . node:7-alpine
/var/jenkins_home/workspace/0109deploy01@2@tmp/durable-4b089662/script.sh: 1: docker: not found

排查:
进入jenkins容器

kubectl exec -it -u root -n jenkins         jenkins-56dfcc9456-h4kqs  -- bash

进入后执行

docker -v

提示:

bash: docker: command not found

所以报错原因,在jenkins容器中没有安装docker

解决方案:
把docker 配置到容器中,在jenkins的yaml中添加以下内容

    - mountPath: /var/run/docker.sock
      name: dockersock
    - mountPath: /usr/bin/docker
      name: docker



  - hostPath:
      path: /usr/bin/docker
      type: ""
    name: docker
  - name: jenkins-admin-token-nqbkc
    secret:
      defaultMode: 420
      secretName: jenkins-admin-token-nqbkc

如果还不行,在jenkins插件管理中安装docker相关插件

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐