1

Im trying to run my pipeline through Jenkins and not able to execute any commands using "sudo". Getting the following error when sudo is encountered :

sudo: you do not exist in the passwd database

Follwing the Dockerfile which Im using for setting up the Jenkins slave.

FROM openjdk:8-jdk

RUN apt-get update -y && apt-get install -y curl sudo
#Install docker
RUN curl -sSL https://get.docker.com/ | sh
ARG user=jenkins
ARG group=jenkins
ARG uid=10000
ARG gid=10000

ENV HOME /home/${user}
RUN groupadd -g ${gid} ${group}
RUN useradd -c "Jenkins user" -d $HOME -u ${uid} -g ${gid} -m ${user}
RUN usermod -aG docker ${user}
RUN usermod -aG sudo ${user}
RUN usermod -aG root ${user}

ARG VERSION=3.20
ARG AGENT_WORKDIR=/home/${user}/agent

RUN apt-get install -y zip unzip sudo 
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
RUN unzip awscliv2.zip
RUN ./aws/install -i /usr/local/aws-cli -b /usr/local/bin

RUN mkdir $HOME/.docker \
  && chmod 777 $HOME/.docker/
RUN curl --create-dirs -sSLo /usr/share/jenkins/slave.jar https://repo.jenkins-ci.org/public/org/jenkins-ci/main/remoting/${VERSION}/remoting-${VERSION}.jar \
  && chmod 755 /usr/share/jenkins \
  && chmod 644 /usr/share/jenkins/slave.jar

#docker compose cli
RUN curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose \
    && chmod +x /usr/local/bin/docker-compose
    
COPY jenkins-slave /usr/local/bin/jenkins-slave
RUN chmod 777 /usr/local/bin/jenkins-slave

RUN echo 'jenkins ALL=(ALL) NOPASSWD:ALL'| sudo EDITOR='tee -a' visudo

USER ${user}
ENV AGENT_WORKDIR=${AGENT_WORKDIR}
RUN mkdir /home/${user}/.jenkins && mkdir -p ${AGENT_WORKDIR}

VOLUME /home/${user}/.jenkins
VOLUME ${AGENT_WORKDIR}
WORKDIR /home/${user}

ENTRYPOINT ["/usr/local/bin/jenkins-slave"]
ASHISH M.G
  • 522
  • 2
  • 7
  • 23
  • i didn't understand you setup yet. What is your scenario you want to cover. In best case you don't need root. Maybe another solution works fine as well – Manuel Feb 10 '21 at 15:53
  • @ManuelPolacek For example...I didnt have zip package or helm already installed in my jenkins, so I was looking to do sudo apt-get install zip or install helm. Then I get this error. Im pretty new to Jenkins . So to do installations I then add the installations to the Dockerfile and redeploy the slave dockerfile everytime i need something to be installed – ASHISH M.G Feb 10 '21 at 16:17
  • If you want to setup Jenkins as master slave, that slaves spawn when needed, you can follow this setup: https://medium.com/swlh/quick-and-simple-how-to-setup-jenkins-distributed-master-slave-build-on-kubernetes-37f3d76aae7d . I setup it on my local environment like this and within the build pipeline i can spawn any image i want. So there's actually no need for root privileges. Just run a container with kubectl inside, or docker in docker or helm. Or whatever is needed. – Manuel Feb 10 '21 at 16:40

0 Answers0