0

I have jenkins deployed via helm charts on kubernetes cluster Now i want to be able to run helm to deploy helm charts applications on my kubernetes cluster and have the following in my jenkinsfile

pipeline {
    agent {
        docker { image 'alpine/helm' }
    }
    stages {
        stage('Deploy') {
            steps {
                sh 'helm ls'
            }
        }
    }
}

I also get kubernetes authentication setup on my jenkins so connection to cluster is fine but the error am getting now is the following

+ docker inspect -f . alpine/helm

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.38/containers/alpine/helm/json: dial unix /var/run/docker.sock: connect: permission denied
[Pipeline] isUnix
[Pipeline] sh
+ docker pull alpine/helm
Using default tag: latest
Warning: failed to get default registry endpoint from daemon (Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.38/info: dial unix /var/run/docker.sock: connect: permission denied). Using system default: https://index.docker.io/v1/
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.38/images/create?fromImage=alpine%2Fhelm&tag=latest: dial unix /var/run/docker.sock: connect: permission denied
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE

What am i missing and how to i get out of this error?

Thanks

UPDATE

below are the additions/changes to default values.yaml file of the stable/jenkins helm chart

agent:
  enabled: true
  image: "joao29a/jnlp-slave-alpine-docker"
  tag: "latest"
  customJenkinsLabels: []
  # name of the secret to be used for image pulling
  imagePullSecretName:
  componentName: "jenkins-slave"
  #privileged: false
  privileged: true

  resources:
    requests:
      cpu: "512m"
      memory: "512Mi"
    limits:
      cpu: "512m"
      memory: "512Mi"
  # You may want to change this to true while testing a new image
  alwaysPullImage: false
  # Controls how agent pods are retained after the Jenkins build completes
  # Possible values: Always, Never, OnFailure
  podRetention: "Never"
  # You can define the volumes that you want to mount for this container
  # Allowed types are: ConfigMap, EmptyDir, HostPath, Nfs, Pod, Secret
  # Configure the attributes as they appear in the corresponding Java class for that type
  # https://github.com/jenkinsci/kubernetes-plugin/tree/master/src/main/java/org/csanchez/jenkins/plugins/kubernetes/volumes
  # Pod-wide ennvironment, these vars are visible to any container in the agent pod
  envVars: []
  # - name: PATH
  #   value: /usr/local/bin
  volumes:
  # - type: Secret
  #   secretName: mysecret
  #   mountPath: /var/myapp/mysecret
   - type: HostPath
     hostpath: /var/run/docker.sock
     mountPath: /var/run/docker.sock

everything else pretty much same except for ingress hostnames and admin user password...above is most important modification to default values.yaml file

1
  • Did you able to resolve this issue? I am facing the same and run 'usermod -aG docker jenkins' did not worked for me
    – semural
    Feb 11, 2022 at 12:28

1 Answer 1

2

You need to add the jenkins user to the docker group:

# run the following command as root
usermod -aG docker jenkins
4
  • as i mentioned i am running jenkins server itself on kubernetes cluster..which means i will have to ssh on the worker nodes to run that command on all the nodes...so not sure if this is a good practice..i mean point of jenkins is automation..running that command is very hacky and manual and looking for a better solution to that...except if that is ONLY solution or way around it which i highly doubt
    – uberrebu
    Jan 20, 2020 at 13:11
  • Sorry, I read your question a bit too fast... So Jenkins is running in a container inside your Kubernetes cluster ? Could you add your values.yaml ?
    – Hedi Nasr
    Jan 20, 2020 at 14:14
  • values.yaml is pretty much default with some additions..will update question with those additions
    – uberrebu
    Jan 20, 2020 at 14:19
  • ok updated with what i added to values.yaml file
    – uberrebu
    Jan 20, 2020 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.